Thread trong Java

Chia sẻ bởi Trần Văn Thái | Ngày 19/03/2024 | 8

Chia sẻ tài liệu: Thread trong Java thuộc Tiếng anh 12

Nội dung tài liệu:

Session 1
Module1 – Introduction to Thread
Advanced Java / Session1 / 2 of 13
Module 1
Introduction to Thread
2
A Guide To Advanced Java – Module 1
Objectives
Advanced Java / Session1 / 3 of 13
Define Threads
A Guide To Advanced Java – Module 1
3
Advanced Java / Session1 / 4 of 13
A Guide To Advanced Java – Module 1
4
Advanced Java / Session1 / 5 of 13
Creating Threads
Sub classing Thread
Creating subclass
Overriding the run() method
Starting the thread
Using the Runnable interface
Implementing the Runnable interface
Implementing the run() method
Starting the thread
A Guide To Advanced Java – Module 1
5
Advanced Java / Session1 / 6 of 13
Thread states
A Guide To Advanced Java – Module 1
6
Advanced Java / Session1 / 7 of 13
Methods of the Thread class
The getName() method helps to retrieve the name of the current thread
The setName() method assigns a name to a thread
The start() method allocates the system resources necessary to run the thread and executes the run() method of its target object
The run() method contains instructions, which are executed on the start() method is invoked
A Guide To Advanced Java – Module 1
7
Advanced Java / Session1 / 8 of 13
Methods of the Thread class …
A Guide To Advanced Java – Module 1
8
Advanced Java / Session1 / 9 of 13
Methods of the Thread class …
A Guide To Advanced Java – Module 1
9
Advanced Java / Session1 / 10 of 13
Managing Thread
Thread priority
Thread.MAX_PRIORITY : constant value of 10
Thread.NORM_PRIORITY : constant value of 5, default
Thread.MIN_PRIORITY : constant value of 1
Methods:
setPriority()
getPriority()
A Guide To Advanced Java – Module 1
10
Thread priority helps the thread scheduler to decide which thread to run
Priority also helps the OS to decide the amount of resource that has to be allocated to each thread
Advanced Java / Session1 / 11 of 13
Daemon Threads
setDaemon() method
isDaemon() method
A Guide To Advanced Java – Module 1
11
Advanced Java / Session1 / 12 of 13
Needs for Daemon Thread
A Guide To Advanced Java – Module 1
12
Advanced Java / Session1 / 13 of 13
Module1 - Summary
A Guide To Advanced Java – Module 1
13
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...

Người chia sẻ: Trần Văn Thái
Dung lượng: | Lượt tài: 0
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)