• Post Reply Bookmark Topic Watch Topic
  • New Topic

tomcat response is getting delayed when compared to standalone java application...

 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application, I need to write a program to
get the response from an external url. I have used
the following code and its working fine when running
from a main() method.While running the same piece
of code within a utility class inside tomcat,the response is
getting delayed.
Is it possible to aviod this delay inside tomcat ?
Here is my piece of code...

URL serverAddress = new URL(this.requestURL);
connection = null;
//Set up the initial connection
HttpURLConnection connection = (HttpURLConnection)serverAddress.openConnection();
connection.setDoOutput(true);
connection.connect();
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sb = new StringBuilder();

while ((line = rd.readLine()) != null)
{
sb.append(line + '\n');
}

All suggestions are welcome...
Thanks in advance
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing wrong with the code.

Keep in mind that:

1. The servlet may not be loaded when the request arrives.
2. Tomcat may be running other requests

Exactly how much delay are we talking about?

Bill
 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:There is nothing wrong with the code.

Keep in mind that:

1. The servlet may not be loaded when the request arrives.
2. Tomcat may be running other requests

Exactly how much delay are we talking about?

Bill


Thanks for reply .Actually its taking more than 1 min. delay . Is it possible to reduce this delay?
or is there any available techniques in tomcat , which helps us to do so...

Thanks
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no inherent reason it should be slower in tomcat.

You need to give more details if you want an answer. Is the server heavily loaded? Can you test this on a server that has no other traffic (a local tomcat)? Is the tomcat server making a request to itself or to another server? Is the request you are making to a tomcat server that you have control over? If so, can you write to the log when you get the request and also when the request is over? Do you own the jsp/servlet you are making a request to? Can you write to the log from it? What else have you tried?
 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
steve souza wrote:There is no inherent reason it should be slower in tomcat.

You need to give more details if you want an answer. Is the server heavily loaded? Can you test this on a server that has no other traffic (a local tomcat)? Is the tomcat server making a request to itself or to another server? Is the request you are making to a tomcat server that you have control over? If so, can you write to the log when you get the request and also when the request is over? Do you own the jsp/servlet you are making a request to? Can you write to the log from it? What else have you tried?


My server is not heavily loaded. The server is making request to another server . Also I have full control on the server I am using to make request.
I have written the log and found that the program is delaying at the line
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
Also,I am not the owner of jsp/servlet to which I am requesting ...
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!