Methods of Thread class

1. public void start()

starts thread to begin execution, JVM calls run method of this thread.

IllegalThreadStateException – if the thread was already started.

2. public void run()

run method is used to perform operations by thread.

3. public final void setName(String name)

Changes the name of the thread.

name – new name for this thread.

4. public final String getName()

Returns this thread’s name.

5. public final void setPriority(int newPriority)

Changes the priority of the thread.

IllegalArgumentException – If the priority is not in the range MIN_PRIORITY to MAX_PRIORITY.

6. public final int getPriority()

Returns thread’s priority.

7. public final void join()

The current thread invokes this method on a second thread, causing the current thread to block until the second thread terminates.

8. public final void join(long millisec)

The current thread invokes this method on a second thread, causing the current thread to block until the second thread terminates or the specified number of milliseconds passes.

9. public final void setDaemon(boolean on)

Marks this thread as daemon thread if on is true.

10. public final boolean isDaemon()

Returns true if thread is daemon.

11. public final boolean isAlive()

returns true if thread is alive.

12. public long getId()

Returns the ID of the thread(A long number generated at the time of thread creation).

13. public void interrupt()

Interrupts this thread and causing it to continue execution if it was blocked.

14. public boolean isInterrupted()

Returns true if thread is interrupted else return false.

15. public static void dumpStack()

Prints a stack trace of the current thread.

16. public static void sleep(long millis)

Causes the currently executing thread to sleep for the specified number of milliseconds.

17. public static void yield()

Causes the currently executing thread object to temporarily pause and allow other threads to execute.

18. public static Thread currentThread()

Returns a reference to the currently running thread.   Next Topic: Thread scheduling in java with example. Previous Topic: Way of creating thread in java.

Please follow and like us:
Content Protection by DMCA.com