Creating thread
- There are two way to create a thread
1) By extending Thread class
2) By implementing Runnable interface
1. Runnable interface
- Runnable interface have only one method named run()
1) run()
- It is used to perform action for a thread
2. Starting a thread
1) start()
- It is used to start a newly created thread
- It performs following task
a. A new thread starts(with new callstack)
b. The thread moves from New State to the Runnable state
c. When the thread gets a chance to execute, its target run() mehtod will run
3. By extending Thread class
4. By implementing Runnable interface
- If you are not extending the Thread class, your class object would not be treated as a thread object
- you need to explicitely create Thread class object
'Back-End > Java_1' 카테고리의 다른 글
[Java] Sleeping a thread (0) | 2016.10.07 |
---|---|
[Java] Thread Scheduler (0) | 2016.10.07 |
[Java] Life cycle of a thread (0) | 2016.10.05 |
[Java] Multithreading in java (0) | 2016.10.05 |
[Java] Call by value (0) | 2016.09.13 |