When I write Thread.currentThread().join();
I can't execute code after that line.
If I removed it, I get error.
Is there similar of that line that let me execute the rest of my code.
Asked
Active
Viewed 372 times
0

Manel Chaabene
- 187
- 1
- 3
- 14
-
We'll need to see what you've done. This question is very vague – Roel Strolenberg May 03 '16 at 15:20
-
http://stackoverflow.com/questions/37006829/how-start-remote-webdriver-after-regitering-a-node-in-a-hub My full code is in that post – Manel Chaabene May 03 '16 at 15:24
-
@ManelChaabene please post a [minimal, complete, verifiable example](http://www.stackoverflow.com/help/mcve). Almost all of that code is irrelevant to the issue in this question (e.g. [this code](http://ideone.com/Xl4TeM) replicates the issue). – Andy Turner May 03 '16 at 15:25
-
In the linked question, there seems to be an attempt to have the program wait indefinitely, but instead of using some infinite loop, it just invokes `Thread.currentThread().join()`, for which I can't for the love of me find any usefulness, unless maybe coupled with a `catch` block for `InterruptedException`. – Mena May 03 '16 at 15:27
-
Why would you not expect `Thread.currentThread().join()` to block until interrupted? What did you expect it to do? – Peter Lawrey May 03 '16 at 15:28
-
1@Mena I've seen a couple of questions recently, like this one, where people invoke methods on `Thread.currentThread()` that I'd never have even thought to try. – Andy Turner May 03 '16 at 15:28
-
@AndyTurner weird... – Mena May 03 '16 at 15:28
1 Answers
4
Thread.join
waits for a given thread to complete (to "die" is the expression used in the docs) and resumes the current execution thereafter.
If you are joining the current thread (Thread.currentThread()
), you're essentially waiting forever, unless an InterruptedException
is caught and handled in a way that would make execution stop.
Note that whichever "error" you are getting in the lines following this is likely unrelated, and would caution a new question.

Mena
- 47,782
- 11
- 87
- 106