This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Manage timeouts on a method invoking? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Manage timeouts on a method invoking?" Watch "Manage timeouts on a method invoking?" New topic

Manage timeouts on a method invoking?

sumanth kumar

Joined: Jul 29, 2005
Posts: 22
we have web application which calls database call to retrieve thousands of records, it causing the server crashes due to timeout (its reasonable as per requirement) after 2 to 3 mins abruptly the server crashes and shows server crash report (which may confuse the user). hence, I want to wrap that method invocation with timer set (for 30 secs) code, wait until reaches that time and send a meaning error message to the client.

I tried with Thread class but the method .stop() is deprecated so what is the other way to do ?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

Use an ExecutorService (through Executors). Submit a Callable or Runnable with your code, then use the timed get method.

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: Manage timeouts on a method invoking?
Similar Threads
Question Regarding Destroy Method
Java.exe Application Error
destroy() for Servlet
threads in servlets
NX:Client crashed cause deadlock in LockManager