I wrote a java app to communicate with a web application using XML. After deployment, I found out it takes too long to parse the XML generated by the web application.
For example, it takes about 2 minutes to login; the login information is included in the url. The web application does its processing and responds to the Java app whether the login was successful using XML returned.
I used the standard java DOM parsing.
Is there a way I can optimize this process so that activities can be faster?
What @Nathan said, plus I suggest doing some random pausing while it's taking so much time. I've run into this in the past, and discovered it wasn't the parsing that was taking the time, but the creation and manipulation of data structure as it parsed. You may see something different, but chances are it's a surprise.
I've runned into the same issue and managed to speed up parser by switching off all validation that DocumentBuilder will do by default:
The parse method takes all the time because it's waiting on the input from the other application. You need to separate the two so you can see what's going on. Read the XML from the other application into a ByteArrayOutputStream, then when that's done, copy the output stream to an input stream (you can use commons-io for that) and feed that to the parser. Then see what is really taking all the time.
One thing that you could optimize is your login process. You could use an LDAP server to do authentication against, LDAP is optimized for reads and you can access it with JNDI.
Using a standard XML parser a short message should be parsed in about one milli-second. Using a custom parser you can cut this to about 20 micro-seconds. Any time longer than this is not in the XML parsing