0% found this document useful (0 votes)
19 views

Java Thread: A Thread That Is Created Whenever A JVM Starts

Threads allow a program to split into multiple execution paths or threads that can run concurrently. There are two types of threads: user threads that are created manually and daemon threads that are created by the JVM. The main thread is a user thread that executes first, and it can create other user threads; the program will not terminate until all user threads have finished.

Uploaded by

Shafiqul Islam
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Java Thread: A Thread That Is Created Whenever A JVM Starts

Threads allow a program to split into multiple execution paths or threads that can run concurrently. There are two types of threads: user threads that are created manually and daemon threads that are created by the JVM. The main thread is a user thread that executes first, and it can create other user threads; the program will not terminate until all user threads have finished.

Uploaded by

Shafiqul Islam
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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