• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to time out :confused:

 
Srini Kesavan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to exit out of the program if a method call is taking too much time to process.
How can I do that?
Example:-
IData outputDocument = invoke(context, inputDocument);
if the invoke is taking more than 10 secs. I would like to exit out of the program.
Any help will be useful.
Thanks in advance
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Immediately before calling the long-running method, start a new Thread running which sleeps for the longest possible time, then exits the program. When the method completes, stop the thread.

If t.interrupt() is called within 10 seconds, the app will continue; otherwise it will exit.
 
Srini Kesavan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help. Really appreciate it.
 
Gaurav Mac Mathur
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree this possibally teh best possible solution, but let me warn you that the Sleep time may not be what you prescribe in the code, As thread prioriy are JVM implementation dependent.
_based on my Theoratical Knowledge_
Cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic