java-inter-thread communication
Thread Communication
Is that multiple threads operate on the same resource, but the action is different
two stop thread:
Control the loop of run to control thread end
When the thread is frozen, the tag is not read and the thread does not end
Interrupt Interrupt function : from frozen state to run state, forced transition state throws interrupt exception
When a frozen thread is returned to a running state without a specified way, the frozen state needs to be clear
Forced to revert to the running state. This allows you to manipulate the tag so that the thread ends
three common Thread class methods:
Setdaemon (Boolean):
is marked as a daemon thread or user process, and the Java virtual machine exits when a running thread is a daemon thread.
The method must be called before the thread is started.
join (): must wait for the current thread to finish executing, the current thread holds CPU execution, and then switches to the main thread (before the main thread is frozen)
When a thread executes the Join method to the B thread, the a thread waits until the B thread finishes executing
Can be used to temporarily join thread execution
toString ():
Returns the string representation of the thread, including the thread name, priority, and thread group.
setpriority (): priority, default 5, can be the priority of a thread
These three commonly used
1 min_priority,
5 nom_priority,
Ten max_priority
yield (): pauses the currently executing thread object and executes other threads
Four thread replenishment
Threads that hold waiting threads in the thread pool
In a wait-wake mechanism (semaphore), the resource class in which multiple threads communicate with each other should use
While flag
notifyall Notification wakeup thread pool thread
Synchronization Functions
Such as:
Copyright NOTICE: Welcome to communicate the error of the article, must humbly accept, QQ872785786
java-Inter-thread communication