thread timeout question

M

Marc E

All,
I've got what I imagine is an extremely common problem and so I'm assuming
there's a preferred method of handling this.

Program runs as TimerTask. runs every 5 seconds or so
spawns thread 1
spawns thread 2
spawns thread 3
....etc
Repeat this process per the timer

thread 1 is off and away. same with 2 and 3.

What i need to do is have the threads timeout after a certain period, but
have some additional code run should the timeout be reached before the
thread actually achieved all of its work. So if thread1 takes 20 minutes,
and my timeout is 20 minutes, then at that time, stop trying to do what it
was trying to do and do some cleanup work. if it only takes a minute, then
terminate normally.

is this simply a matter of instead of having thread 1 do the work, that
thread 1 actually spawns thread 1a, which does the work, and thread1 calls
thread1a.join();

Or is there a different/better/preferred way?

I'm running this on the latest JDK, for what it's worth.

Thanks for guidance.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,842
Latest member
MableIwk73

Latest Threads

Top