Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set timeout on a method

Status
Not open for further replies.

mackey333

Technical User
May 10, 2001
563
US
Is there an easy way to code the following: "If this method does not finish executing within 5 seconds, then throw an exception and move on"?

-Greg :-Q

flaga.gif
 
Clearly depends on the method you're executing, but I wouldn't say there's one.

Cheers,
Dian
 
Well I just need to use something one time for testing purposes. I am turning a C program which is currently being called by creating a new process and grabbing its output into a Java class which is built into the program. The problem is sometimes the C program craps out. I am trying to test the results of the Java and C program side by side and don't want to have to watch it run on 500,000 different pieces of data and alt+ctrl+del the C process when it hangs.

-Greg :-Q

flaga.gif
 
Hey all thanks for the suggestions. I ended up just copying and pasting the method code into a run() method and starting a new thread. Then I used:

Code:
Thread myThread...
myThread.start();
Thread.sleep(5);
myThread.stop();

Its a little messy but it is working for my purposes, hopefully it makes it through the weekend haha..






-Greg :-Q

flaga.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top