aspose file tools*
The moose likes JSP and the fly likes How to prevent timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to prevent timeout" Watch "How to prevent timeout" New topic
Author

How to prevent timeout

L John
Greenhorn

Joined: Jun 14, 2004
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61196
    
  66

it takes on an average about 15 minutes to build this hashtable


15 minutes? How are you building it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
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.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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...


42
L John
Greenhorn

Joined: Jun 14, 2004
Posts: 7
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

Joined: Jan 17, 2003
Posts: 68
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

Joined: Dec 21, 2012
Posts: 12

Use 0 value for session timeout, the session never timeout.

Click below link

How to avoid session timeout in jsp


UdayKiran Pulipati
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61196
    
  66

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

Joined: Dec 21, 2012
Posts: 12

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

Joined: Dec 21, 2012
Posts: 12

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to prevent timeout