• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread(s) Suspension and Resuming

 
Alex Givant
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to implement following logic:
- Number of Business Process (BP) run using 1 or more threads each.
- We need to implement suspend/resume for BP
- Suspend should suspend all thread(s) belong to chosen BP
- Resume should resume all thread(s) belong to this BP
Each thread in BP in run() method has some useful functionality, so it's impossible to make while(true) and check if the thread should be suspended or resumed.
Any idea how to implement that? All comments/ideas/hints will be grateful appreciated.
 
Alex Givant
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be I need to clarify that: in run() method of the Thread belongs to BP we call some synchronous method and after we return from it, run() finished and thread should be released back to thread pool. So we need to suspend/resume thread(s) during this synch call.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, if you haven't already, I suggest reading Why Are Thread.stop, Thread.suspend,
Thread.resume and Runtime.runFinalizersOnExit Deprecated?
You probably don't want to use these methods. I'd suggest creating your own custom methods that do something similar in more controlloed fashion. Don't say "suspend" and "resume" though, that will confuse people. Maybe pause() and restart(). You will want to create a Thread or Runnable that has these additional methods - maybe something like an AbstractPausableThread class or a Pausable interface. Either way, when you write a specific implementation of Pausable you will need to write a run() method that periodically checks to see if pause() has been called, and if so (and it's a convenient time to do so without breaking anything) then pause until reastart() is called. (A wait/notify is probably appropriate here.) How often you check the pause status is up to you, and really depends on what sort of work the run() method is doing. (See some discussion of examples in the first link I posted.) Can't say much more in general. Good luck.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!