From the course: Parallel and Concurrent Programming with Java 1

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Thread attributes: Java demo

Thread attributes: Java demo - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 1

Start my 1-month free trial

Thread attributes: Java demo

- [Instructor] In addition to a threads state, which can be retrieved using the getState() method, there are a few other useful properties and methods for java threads that are good to know. If you need to access the thread that's currently executing, you can use the currentThread() method, which returns a reference to the currently executing thread object. Whenever a new thread gets created, it will be assigned a thread ID. This is a positive long number that serves as a unique identifier for the thread, and remains unchanged during it's lifetime. That thread ID can be retrieved using the getID() method. Now, keep in mind that after a thread terminates, that ID number will be available for other new threads to reuse. Another related property is the threads name, which is a string that can be used for identification purposes. Now, more than one thread can have the same name, but they'll never have the thread ID. There are several variations of the thread constructor method that allow…

Contents