aspose file tools*
The moose likes Threads and Synchronization and the fly likes Whether using Threads join correctly or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Whether using Threads join correctly or not" Watch "Whether using Threads join correctly or not" New topic
Author

Whether using Threads join correctly or not

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

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




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

Joined: Sep 20, 2010
Posts: 3378
    
    9
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whether using Threads join correctly or not
 
Similar Threads
CODE WITH SOME MODIFICATIONS REGARDING JOIN
generics code mixed with legacy collection
Evidence 4 Main Thread dead after main method exits
Regarding Join method in Threads
[ A good finding ] - User & Deamon Threads