0% found this document useful (0 votes)
7 views1 page

Java Multi-Threading Basics Explained

The document discusses multi-threading in Java. It explains that Java programs are single threaded by default but allow for multiple threads through the Thread class and Runnable interface. Threads can be created by inheriting from Thread or implementing Runnable. The Thread class provides methods for creating, naming, starting, sleeping, suspending, and resuming threads. Threads go through life cycle states of born, ready, runnable, block, and dead. Thread priority can be set from 1 to 10 with default of 5 using setPriority and getPriority methods.

Uploaded by

alibaba_a5b
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Java Multi-Threading Basics Explained

The document discusses multi-threading in Java. It explains that Java programs are single threaded by default but allow for multiple threads through the Thread class and Runnable interface. Threads can be created by inheriting from Thread or implementing Runnable. The Thread class provides methods for creating, naming, starting, sleeping, suspending, and resuming threads. Threads go through life cycle states of born, ready, runnable, block, and dead. Thread priority can be set from 1 to 10 with default of 5 using setPriority and getPriority methods.

Uploaded by

alibaba_a5b
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

31.07.

2008
Multi-Threading
- A light weight process within a process
- Each Java program is single threaded by default
- One thread is always present called as main thread
- Java provides a Thread class and Runnable interfaces for implementing the
multi-threading
- Runnable interfaces provide run() method to define the working of thread
- Threading can be implanted using two methods
o By inheriting Thread class
o By implementing the Runnable interface

Thread class
- To create and locate the threads
o Thread(Runnable r)
o Thread(Runnable r, String name)
o static Thread currentThread()
o String getName()
o void setName(String name)
o void start() – To add the thread in Thread queue
o void run() – To provide working to the thread
o static void sleep(int ms) throws InterruptedException
o static void sleep(int ms,int ns) throws InterruptedException
o void suspend() – To block state till resume() get called
o void resume() – To go back to ready state
o static void yield() – To provide control to CPU

Life Cycle of Thread


1. Born State
2. Ready State
3. Runnable State
4. Block State
5. Dead State

Priority
- Min Priority 1
- Max 10
- Default 5
- Methods
o setPriority(int n)
o int getPriority()

You might also like