You are on page 1of 3

Java Thread

1.

Thread is an individual path of execution.

2.

By Using thread we can logically divide a program using several segments.


These segments can execute concurrently.

3.

Threads are sometimes called lightweight processes.

4.
All the threads are created directly or indirectly from "java.lang.Thread"
class.
5.

6.

Threads can be created in the following ways:


a.

By extending the "java.lang.Thread" class.

b.

By implementing the "java.lang.Runnable" interface.

There are two kinds of threads are available:


a. User thread:

a thread that is created manually in the program.

b. Daemon thread: a thread that is created whenever a JVM starts.


7.

8.

A thread, called main thread, is automatically created when JVM calls the
main method, is a user thread. From the main thread, other user threads
can be created.
After the execution of the main thread, if other user threads finishes
already, the program exits. Otherwise, other user threads start execution.

9.

As long as any of the user threads are alive, daemon thread is alive.

10.

Daemon thread dies if JVM stops.

11.

The Thread class has the following useful constructors:


Thread()
Thread(Runnable obj)
Thread(Runnable obj, String threadName)

12.

The Thread class has the following methods:


void setName(String name)
String getName()
Thread getCurrentThread()
public void start()
public void run()
void setPriority(int p) // starts from 1(MIN) to 10(MAX), default 5
int getPriority()
public static void sleep(int milisecond)
yield()
join()

13.

Important methods of java.lang.Object class:


wait()
notify()

notifyAll()

You might also like