Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to prevent timeout

 
L John
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a jsp page that generate a hashtable and display its key-value pairs back to the browser. The problem is that it takes on an average about 15 minutes to build this hashtable, and as a result, I always get a timeout error. Can anyone give me suggestions as to what can I do to avoid getting the timeout error without changing the server configuration for timeout?

Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64969
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it takes on an average about 15 minutes to build this hashtable


15 minutes? How are you building it?
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changing the server configuration will not help you. the browser will timeout and there is nothing you can do about this. You will have to figure out a threaded solution such as kicking off a thread in a servlet that constructs the HashMap. Check back with the servlet and check to see if the HashMap is finished loading.

This is a pretty crappy way of doing things though. What exactly are you doing so that it takes this long to populate this Map? If it is a data problem (e.g. there is a ton of data to load) then you need to find a better solution such as paging or something.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better solution still would be caching.
Have a background process running in the web app that creates the Map and say once every several hours reconstructs it (leaving the existing one in place until reconstruction is complete).
Make that cached Map available to the rest of the application through some mechanism (a servlet, EJB, or a static method in the generating class for example).

Make sure the first Map is available when the application starts accepting connections...
 
L John
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for all the responses. Actually, we didn't write the class that builds this hashtable. It was written by a third-party in our contract. I think it took so so long for the hashtable to build was because some datasources were down or unreachable (I guess it took a long time for the app to give up trying) which caused the delay.
 
Ram Kumar Subramaniam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was something similar discussed in the forums somewhere. The same idea was implemented in our project

But the first thing would be see if you could reduce the response time for the request.

1.) Reload the page ever x sec using javascript(setTimeout) with a flag to indicate page is being reloaded. for eg add a new parameter reload=true only when reloading. When first invoked make sure the reload parameter does not exist.

2.) In your server side code

if(request.getParameter("reload") != null) {
String dataProcessed = session.getAttribute("dataProcessed");
if(dataProcessed == null){
//flush some output
printWriter.println("<html><body><h1>Loading data</h1></body></html>");
printWriter.flush();
return;
}
} else {
///indicates first call to server.
///load the data
///once data is loaded
session.setAttribute("dataProcessed", "dataProcessed");
printWriter.println("<html><body><h1>Loading data</h1></body></html>");
printWriter.flush();
return;//make sure u return here.
}
session.removeAttribute("dataProcessed");
[ June 29, 2004: Message edited by: Ram Kumar Subramaniam ]
 
udaykiran pulipati
Greenhorn
Posts: 12
Hibernate Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use 0 value for session timeout, the session never timeout.

Click below link

How to avoid session timeout in jsp
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64969
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
udaykiran pulipati wrote:Use 0 value for session timeout, the session never timeout.

Click below link

How to avoid session timeout in jsp


That will not help. He's asking about the browser timeout, not the session timeout.
 
udaykiran pulipati
Greenhorn
Posts: 12
Hibernate Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add below config in web.xml for get rid of session timeout.

<session-config>
<session-timeout>-1</session-timeout>
<!-- session never timeout -->
</session-config>

Click below link

How to avoid session timeout in jsp
 
udaykiran pulipati
Greenhorn
Posts: 12
Hibernate Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
udaykiran pulipati wrote:Use 0 value for session timeout, the session never timeout.

Click below link

How to avoid session timeout in jsp


That will not help. He's asking about the browser timeout, not the session timeout.



I gave solution to his problem. I also face this problem previously, after adding session - config in web.xml the problem is solved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic