What is the significance of Thread.currentThread()
I've tried looking it up but I'm not sure what it's actually doing.
Daniel Whyte
Level 17
Thread.currentThread()
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Nouser
23 February 2021, 08:49
What this is for instances is Thread.currentThread() for threads. It returns the threads reference variable in the environment the code is called.
When you create and start a thread in the main method, you have a Thread reference variable (t in the example)
The now running thread doesn't know about that reference variable anymore as you didn't pass it. But you have the possiblity to get it with currentThread() and now you can call methods on that object again, like isInterrupted or sleep.
+1