Giới thiệu về Thread trong java

Chia sẻ bởi Nguyễn Văn A | Ngày 29/04/2019 | 56

Chia sẻ tài liệu: Giới thiệu về Thread trong java thuộc Bài giảng khác

Nội dung tài liệu:

Module 1
Introduction to Thread
Objective
Define Threads
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
Thread states
Methods of the Thread class
The currentThread() method returns the thread running.
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 when the start() method is invoked.
Methods of the Thread class …
Methods of the Thread class …
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()
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
Daemon Threads
setDaemon() method
isDaemon() method
Needs for Daemon Thread
Summary
LAB & Exercises
LAB
Extending the Thread class
Implementing the Runnable
Creating the Thread objects
Using sleep() and getName() methods
Displaying Thread class method descriptions
Setting and getting Thread priorities
Exercises
Write a thread displaying an electronic clock
* 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ẻ: Nguyễn Văn A
Dung lượng: | Lượt tài: 1
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)