Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Manage timeouts on a method invoking?

 
sumanth kumar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an ExecutorService (through Executors). Submit a Callable or Runnable with your code, then use the timed get method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic