This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Making a Execution of a tasks take only constant Number of seconds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Making a Execution of a tasks take only constant Number of seconds" Watch "Making a Execution of a tasks take only constant Number of seconds" New topic
Author

Making a Execution of a tasks take only constant Number of seconds

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I have a Report Generation task , so for this i am starting a Thread .
The Report generation should take only 10000 Ms , or otherwise the Action should be terminated




I have coded this way , please tell me whether i can use join in this case ??

Thread thread = new Thread(this);
thread.setDaemon(true);
thread.start();


thread.join(waitSec );



Save India From Corruption - Anna Hazare.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3983
    
  18

Don't use a Thread. Instead, pass your task to an ExecutorService and supply a timeout.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Making a Execution of a tasks take only constant Number of seconds
 
It's not a secret anymore!