It's not a secret anymore!
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: 4087
    
  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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Making a Execution of a tasks take only constant Number of seconds
 
It's not a secret anymore!