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

Joining Two threads

saurabh beriwal
Greenhorn

Joined: Mar 15, 2013
Posts: 2
Hi All ,

How can we join two threads in java? Do we have any way to achieve this other than using join() method?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

saurabh beriwal wrote:Hi All ,

How can we join two threads in java? Do we have any way to achieve this other than using join() method?
Wait, what? You want to join threads without using the mechanism used to join threads? Why?

Define what you want to do, and why you want to do it. Talking about join will probably confuse things, because it is an implementation and not an intent.


Steve
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

Steve Luke wrote:Wait, what? You want to join threads without using the mechanism used to join threads? Why?

Define what you want to do, and why you want to do it. Talking about join will probably confuse things, because it is an implementation and not an intent.



Agreed. Generally, if you want to do something, and the normal way to do that something isn't what is wanted, then perhaps it is best to take a step back and quickly look at what you want, than continuing down the rabbit hole (or arguably, more like a rat hole).

Can you elaborate what you are trying to accomplish at a higher level?

Thanks,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
saurabh beriwal
Greenhorn

Joined: Mar 15, 2013
Posts: 2


Actually I am trying to join two threads created using callable and future. Please let me know if this is achievable.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

saurabh beriwal wrote:

Actually I am trying to join two threads created using callable and future. Please let me know if this is achievable.


Ahh, Callable/Future don't create threads. They are callbacks you can use with Executors to run code in the Threads managed by the Executor and get feedback on when the task is done. If you could get access to the Thread which the Callable is run in, you wouldn't want to join it, because it could never end (in most Executor implementations anyway). What you want to do is wait until the Callable's work is complete. Future has methods that will let you do that. Take a look at the API (in the link) to see.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Joining Two threads