This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Thread Expiry issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread Expiry issue." Watch "Thread Expiry issue." New topic

Thread Expiry issue.

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
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.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20083

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.

How To Ask Questions How To Answer Questions
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Thread Expiry issue.
It's not a secret anymore!