• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Joining Two threads

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic