Constructor Constants Methods The Thread Class

J.E.D.I.

9.3 The Thread Class

9.3.1 Constructor

The thread has eight constructors. Let us have a quick look at some of these constructors. Thread Constructors Thread Creates a new Thread object. ThreadString name Creates a new Thread object with the specified name. ThreadRunnable target Creates a new Thread object based on a Runnable object. target refers to the object whose run method is called. ThreadRunnable target, String name Creates a new Thread object with the specified name and based on a Runnable object. Table 29: Thread constructors

9.3.2 Constants

The Thread class also provides constants for priority values. The following table gives a field summary of the Thread class. Thread Constants public final static int MAX_PRIORITY The maximum priority value, 10. public final static int MIN_PRIORITY The minimum priority value, 1. public final static int NORM_PRIORITY The default priority value, 5. Table 30: Thread constants

9.3.3 Methods

Now, these are some of the methods provided in the Thread class. Thread Methods public static Thread currentThread Returns a reference to the thread that is currently running. public final String getName Returns the name of this thread. public final void setNameString name Introduction to Programming II Page 121 J.E.D.I. Thread Methods Renames the thread to the specified argument name. May throw SecurityException. public final int getPriority Returns the priority assigned to this thread. public final boolean isAlive Indicates whether this thread is running or not. public final void join[long millis, [int nanos]] An overloaded method. The currently running thread would have to wait until this thread dies if no parameter is specified, or until the specified time is up. public static void sleeplong millis Suspends the thread for millis amount of time. May throw InterruptedException. public void run Thread execution begins with this method. public void start Causes thread execution to begin by calling the run method. Table 31: Thread methods

9.3.4 A Thread Example