• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 );


 
Stephan van Hulst
Bartender
Pie
Posts: 5608
55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a Thread. Instead, pass your task to an ExecutorService and supply a timeout.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic