Multithreaded job

< p align = "center" > multithreaded job

2、 Multiple choice questions

3、 Judgment question

Process: the dynamic execution process of a program on a data set. It is the basic unit of resource allocation and the smallest unit of resource allocation. Thread: the basic scheduling unit in a process, the unit of CPU scheduling and execution, and the smallest unit of program execution

Difference: process is the basic unit of operating system resource allocation, while thread is the basic unit of task scheduling and execution

The first method: use the runnable interface to create a thread and override the run method. The second method: directly inherit the thread class to create an object and override the run method

Runnable: the advantage of the interface scheme is to reduce the coupling between classes, but the disadvantage is that the writing is complex

Thread inheritance scheme has the advantages of simple writing and high coupling

(1) synchronous locks are treated differently:

After sleep (), the program does not release the synchronization lock.

After wait(), the program releases the synchronization lock.

(2) different usage:

Sleep () can use the specified time to wake him up automatically. If the time is less than, you can only call interreput () to forcibly interrupt.

Wait () can be invoked directly with notify ().

In, the communication between threads can be realized by calling the wait() method, notify() method or notifyall() method of the object object.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>