Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

object wait(timeout) not timing out  RSS feed

 
G Wiebe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a main thread that creates an object with a Runnable interface, creates a thread out of it and then starts it. The main thread then waits for 180 seconds on the object. If after the timeout period, the object has not done its work, I want to stop the old object, create a new one and try again.
Unfortunately the wait(180000) never times out!!! Thanks for any help.

Glenn

Consumer:

<pre>
RptGetter rmGet = new RptGetter(mSid, mRptMgr, mRptId, mKv, kTagList, mDebugLevel);
Thread rgt = new Thread(rmGet);
rgt.start();
synchronized(rmGet) {
rmGet.wait(180000);
if (!rmGet.done) {
// NOT DONE - stop the thread
rgt.stop();
} else {
// DONE - get report and continue
mTds = rmGet.getTDS();
gotRpt = true;
} // end else if done
</pre>



Producer:
<pre>
class RptGetter implements Runnable {
public void run() {
synchronized (this) {
tds = rptMgr.getReport
done = true;
this.notifyAll();
} // end synchronized code
} // end run method
</pre>


------------------
 
Girish Pednekar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like your consumer thread is waiting to enter the synchronized block rather than in wait() itself. In the producer thread try putting "tds = rptMgr.getReport" statement outside of synchronized block.
thanks
GP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!