• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whether using Threads join correctly or not

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Want to execute a Certain Task to take only 1000 MS , if it exceeds , i dont want to continue with the task ,
i have used join for this .

Please tell me and guide me if this is correct or not

import java.util.List;


ChildTHread


 
Stephan van Hulst
Bartender
Posts: 6318
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, this will not work, because you are waiting on the mainthread to finish, not the childthread. Changing it to to childthread.join(1000) should work. You don't need mainthread.

There are much much better ways to do this though. Take a look at the invokeAll() method of the ExecutorService class.

You are also using raw types. Don't use raw types.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic