Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Expiry issue.

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I need some guidance on threads.

What I want to do, is start a thread, and ask it to complete some operation - if the operation (stuff in my public void run() method) is complete within the timel limit proceed, if however it's still running, then I want to terminate the operation and diplay error such as "time out...."

What I need is a thread expiry method,

I have the code below, how do I go about imnplementing what I want to do?



I think Thread.join(2000) maybe useful - am I on the right track,

Can someone point me to the right example.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A timed join, combined with a status flag (boolean?) would be good:
Please note the volatile keyword; it's quite necessary unless you want to use synchronization.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic