'Back-End/Java_1'에 해당되는 글 48건

donaricano-btn

Call a run() directly instead start()

- Each thread starts in a separate call stack, like this

- Invoking the run() from main thread, the run() method goes onto the current call stack 

1. Problem

- There is no context-switching 

- t1 and t2 will be treated as normal object not thread object


'Back-End > Java_1' 카테고리의 다른 글

[Java] Naming Thread  (0) 2016.10.07
[Java] Joining a thread  (0) 2016.10.07
[Java] Sleeping a thread  (0) 2016.10.07
[Java] Thread Scheduler  (0) 2016.10.07
[Java] Creating thread  (0) 2016.10.05
블로그 이미지

리딩리드

,
donaricano-btn

Sleeping a thread

- It is used to sleep a thread for the specified amount of time


1. Syntax

- public static void sleep(long miliseconds)throws InterruptedExceptioin

- public static void sleep(long miliseconds, int nanos)throws InterruptedException


2. Example


- At a time only one thread is executed

- If you sleep a thread for the specified time, the thread schedular pick up another thread

'Back-End > Java_1' 카테고리의 다른 글

[Java] Joining a thread  (0) 2016.10.07
[Java] Call a run() directly instead start()  (0) 2016.10.07
[Java] Thread Scheduler  (0) 2016.10.07
[Java] Creating thread  (0) 2016.10.05
[Java] Life cycle of a thread  (0) 2016.10.05
블로그 이미지

리딩리드

,
donaricano-btn

Thread Scheduler


1. What is it?

- Thread scheduler is the part of the JVM that decides which thread should run

- Only one thread at a time can run in a single process

- The Thread scheduler mainly uses preemptive or time slicing scheduling to schedule the threads


2. Different between preemptive and time slicing

1) preemptive

- The highest priority task executes until it enters the waiting or dead states

- A higher priority task comes into existence

2) time slicing

- A task executes for a predefined slice of time and then reenters the pool of ready tasks

- The scheduler then determines which task should execute next, based on priority and other factors


'Back-End > Java_1' 카테고리의 다른 글

[Java] Call a run() directly instead start()  (0) 2016.10.07
[Java] Sleeping a thread  (0) 2016.10.07
[Java] Creating thread  (0) 2016.10.05
[Java] Life cycle of a thread  (0) 2016.10.05
[Java] Multithreading in java  (0) 2016.10.05
블로그 이미지

리딩리드

,
donaricano-btn

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
블로그 이미지

리딩리드

,