The Thread Class and the Runnable Interface Java Help

The Thread Class and the Runnable Interface
Java’s multithreading system is built upon the Thread class, its methods, and its companion interface, Runnable. Thread encapsulates a thread of execution. Since you can’t directly refer to the ethereal state of a running thread, you will deal with it through its proxy, the Thread instance that spawned it. To create a new thread, your program will either extend Thread or-implement the Runnable interface. The Thread class defines several methods that help manage threads. The ones that will be used in this chapter are shown here

Method                           Meaning

getName                       Obtain a thread’s name
get Priority                    Obtain a thread’s priority
is Alive                           Determine if a thread is still running
join                                  Wait for a thread to terminate
run                                  Entry point for the thread
sleep                               Suspend a thread for a period of time

start                                Start a thread by calling its run method

Thus far, all the examples in this book have used a single thread of execution. The remainder of this chapter explains how to use Thread and Runnable to create and manage threads  beginning with the one thread that all Java programs have: the main thread.

. .

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 17, 2014 in The Complete Reference

Share the Story

About the Author

Back to Top