• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Joining Two threads

 
saurabh beriwal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
saurabh beriwal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Actually I am trying to join two threads created using callable and future. Please let me know if this is achievable.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic