java-Inter-thread communication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.