- Java.lang - Void
- Java.lang - Throwable
- Java.lang - ThreadLocal
- Java.lang - ThreadGroup
- Java.lang - Thread
- Java.lang - System
- Java.lang - StringBuilder
- Java.lang - StringBuffer
- Java.lang - String
- Java.lang - StrictMath
- Java.lang - StackTraceElement
- Java.lang - Short
- Java.lang - SecurityManager
- Java.lang - RuntimePermission
- Java.lang - Runtime
- Java.lang - ProcessBuilder
- Java.lang - Process
- Java.lang - Package
- Java.lang - Object
- Java.lang - Number
- Java.lang - Math
- Java.lang - Long
- Java.lang - Integer
- Java.lang - InheritableThreadLocal
- Java.lang - Float
- Java.lang - Enum
- Java.lang - Double
- Java.lang - Compiler
- Java.lang - ClassLoader
- Java.lang - Class
- Java.lang - Character.UnicodeBlock
- Java.lang - Character.Subset
- Java.lang - Character
- Java.lang - Byte
- Java.lang - Boolean
- Java.lang - Home
Java.lang Package extras
Java.lang Package Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.lang.Thread Class
Introduction
The java.lang.Thread class is a thread of execution in a program. The Java Virtual Machine allows an apppcation to have multiple threads of execution running concurrently.Following are the important points about Thread −
Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority
Each thread may or may not also be marked as a daemon.
There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread and,
the other way to create a thread is to declare a class that implements the Runnable interface
Class Declaration
Following is the declaration for java.lang.Thread class −
pubpc class Thread extends Object implements Runnable
Field
Following are the fields for java.lang.Thread class −
static int MAX_PRIORITY − This is the maximum priority that a thread can have.
static int NORM_PRIORITY − This is the default priority that is assigned to a thread.
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 |
Thread() This allocates a new Thread object. |
2 |
Thread(Runnable target) This allocates a new Thread object. |
3 |
Thread(Runnable target, String name) This allocates a new Thread object. |
4 |
Thread(String name) This constructs allocates a new Thread object. |
5 |
Thread(ThreadGroup group, Runnable target) This allocates a new Thread object. |
6 |
Thread(ThreadGroup group, Runnable target, String name) This allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group. |
7 | Thread(ThreadGroup group, Runnable target, String name, long stackSize) This allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, and has the specified stack size. |
8 |
Thread(ThreadGroup group, String name) This allocates a new Thread object. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method returns the number of active threads in the current thread s thread group. |
2 | This method determines if the currently running thread has permission to modify this thread. |
3 |
protected Object clone() This method returns a clone if the class of this object is Cloneable. |
4 | This method returns a reference to the currently executing thread object. |
5 | This method prints a stack trace of the current thread to the standard error stream. |
6 | This method copies into the specified array every active thread in the current thread s thread group and its subgroups. |
7 | This method returns a map of stack traces for all pve threads. |
8 | This method returns the context ClassLoader for this Thread. |
9 | This method returns the default handler invoked when a thread abruptly terminates due to an uncaught exception. |
10 | This method returns the identifier of this Thread. |
11 | This method returns this thread s name. |
12 | This method Returns this thread s priority. |
13 | This method returns an array of stack trace elements representing the stack dump of this thread. |
14 | This method returns the state of this thread. |
15 | This method returns the thread group to which this thread belongs. |
16 | This method returns the handler invoked when this thread abruptly terminates due to an uncaught exception. |
17 | This method returns true if and only if the current thread holds the monitor lock on the specified object. |
18 | This method interrupts this thread. |
19 | This method tests whether the current thread has been interrupted. |
20 | This method tests if this thread is apve. |
21 | This method tests if this thread is a daemon thread. |
22 | This method tests whether this thread has been interrupted. |
23 | Waits for this thread to die. |
24 | Waits at most milps milpseconds for this thread to die. |
25 | Waits at most milps milpseconds plus nanos nanoseconds for this thread to die. |
26 | If this thread was constructed using a separate Runnable run object, then that Runnable object s run method is called; otherwise, this method does nothing and returns |
27 | This method sets the context ClassLoader for this Thread. |
28 | This method marks this thread as either a daemon thread or a user thread. |
29 | This method set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread. |
30 | This method changes the name of this thread to be equal to the argument name. |
31 | This method changes the priority of this thread. |
32 | This method set the handler invoked when this thread abruptly terminates due to an uncaught exception. |
33 | This method causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milpseconds, subject to the precision and accuracy of system timers and schedulers. |
34 | This method causes the currently executing thread to sleep (cease execution) for the specified number of milpseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers. |
35 | This method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread. |
36 | This method Returns a string representation of this thread, including the thread s name, priority, and thread group. |
37 | This method causes the currently executing thread object to temporarily pause and allow other threads to execute. |
Methods inherited
This class inherits methods from the following classes −
java.lang.Object