Constructor Constants Methods The Thread Class
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 constructors9.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 constants9.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 methods9.3.4 A Thread Example
Parts
» | Komputasi | Suatu Permulaan
» Object-Oriented Design Class Object Attribute Method
» Constructor Package Encapsulation Abstraction Inheritance Polymorphism Interface
» Declaring Java Classes Declaring Attributes Declaring Methods Declaring a Constructor
» Instantiating a Class Accessing Object Members Packages The Access Modifiers
» Encapsulation Inheritance Overriding Methods
» Abstract Classes and Methods Interface
» The this Keyword The super Keyword
» The static Keyword The final Keyword
» Introduction The Error and Exception Classes An Example
» The try-catch Statements Catching Exceptions
» The finally Keyword Catching Exceptions
» Exception Classes and Hierarchy Checked and Unchecked Exceptions
» What are Assertions? Enabling or Disabling Assertions
» What is Recursion? Recursion Vs. Iteration
» Factorials: An Example Print n in any Base: Another Example
» What is an Abstract Data Type? Stacks Queues
» Sequential and Linked Representation Sequential Representation of an Integer Stack
» Linked Lists Linked Representation of an Integer Stack
» Java Collections Abstract Data Types
» Objectives Objectives Objectives Objectives
» The Math Class | Komputasi | Suatu Permulaan
» String Constructors String Methods
» The StringBuffer Class The String and the StringBuffer Class
» The Wrapper Classes | Komputasi | Suatu Permulaan
» The System Class | Komputasi | Suatu Permulaan
» Objectives Command-Line Arguments and System Properties
» Reading from a File Writing to a File
» Divide-and-Conquer Paradigm Understanding Merge Sort The Algorithm An Example
» Objectives Objectives Abstract Windowing Toolkit AWT vs. Swing
» Fundamental Window Classes AWT GUI Components
» Graphics More AWT Components
» The FlowLayout Manager The BorderLayout Manager
» The GridLayout Manager Panels and Complex Layouts
» Setting Up Top-Level Containers A JFrame Example A JOptionPane Example
» Objectives Event Classes | Komputasi | Suatu Permulaan
» ActionListener Method MouseListener Methods MouseMotionListener Methods WindowListener Methods
» Guidelines for Creating Applications Handling GUI Events Mouse Events Example
» Thread Definition Thread States Priorities
» Constructor Constants Methods The Thread Class
» Extending the Thread Class Implementing the Runnable Interface
» Extending vs. Implementing An Example Using the join Method
» An Unsynchronized Example Locking an Object
» First Synchronized Example Second Synchronized Example
» Producer-Consumer Example Interthread Communication
» The Executor Interface Concurrency Utilities
» The Callable Interface Concurrency Utilities
» The ServerSocket and the Socket Class
» The MulticastSocket and the DatagramPacket Class
» The Applet Life Cycle The paint Method
» Objectives Objectives Applet HTML Tags
» Character and Byte Streams Input and Output Streams Node and Filter Streams
» Reader Methods Node Reader Classes Filter Reader Classes
» Writer Methods Node Writer Classes Filter Writer Classes
» A Basic ReaderWriter Example Modified ReaderWriter Example
» InputStream Methods Node InputStream Classes Filter InputStream Classes
» OutputStream Methods Node OutputStream Classes Filter OutputStream Classes
» A Basic InputStreamOutputStream Example Modified InputStreamOutputStream Example
» The transient Keyword Serialization: Writing an Object Stream
» Objectives Why Generics? | Komputasi | Suatu Permulaan
Show more