Java Concurrent Notes __java

Source: Internet
Author: User

Threading is a way to create transparent, extensible programs.


Thread.yield () is part of the thread scheduler (Java Threading Mechanism), a suggestion that the CPU can be transferred from one thread to another, stating: "I've done the most important part of the lifecycle, and it's time to switch to another task for a while."


You can then obtain a reference to the thread object that is driving the task by calling Thread,currentthread () inside the task. " 2. Generate return value from task

Runnable in a thread is a stand-alone task that performs work, and it does not return any values. If you want the task to return a value when it is finished, implement the callable interface instead of the Runnable interface.

Callable is a generic with a type parameter that represents the value returned from method call () instead of run (), and must be called using the Executorservice.submit () method.

3. Priority thread priority passes the importance of the thread to the scheduler. Although the order of the CPU to handle the existing set of threads is indeterminate, the scheduler will tend to allow higher priority threads to execute first. This does not mean that a thread with a lower priority does not get execution (priority does not cause a deadlock). Lower-priority threads are only performing less frequently. The priority is set at the beginning of run () and not set in the constructor. SetPriority (), getpriority ().   When you adjust the priority, just use max_priority, norm_priority,min_priority. Thread

4. Background thread so-called background (daemon) thread, refers to the running of the program in the background to provide a common service thread. When all non-background threads end, the program terminates and kills all background threads in the process.

Use Xxxx.setdaemon (True) to set the thread as a background thread.

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.