Java Learning notes----Thread 2

Source: Internet
Author: User

The method to get the current thread object is: Thread.CurrentThread ();

When the thread target's Run method ends, it means that the thread finishes

The state of the thread:

1) New state: Thread object has been created, but the Start method has not been called

2) Operational Status: The Start method is called. or after running, from blocking to waiting for sleep after returning.

3) Operation Status: Start running, can see a buffer of the running state when the field can run

4) Wait for sleep blocking state: Frozen state

5) Death, Run method end

To prevent a thread from running:

Sleep: Thread.Sleep ()

The priority of the thread and the concession of the thread:

SetPriority () thread priority between 1~10, default is 5

Thread.yield () is likely to have no effect. Because the concession thread will still be checked by thread scheduling again.

To join a thread:

Join ()

The non-static method of thread join () lets a thread B "join" to the tail of another thread A. b does not work until a is complete.

The join () method also has an overloaded version with a time-out limit. For example, T.join (5000); Let the thread wait 5000 milliseconds, if it exceeds this time, then stop waiting, become operational state



Since synchronization and lock look a little more complicated, the next time specifically to watch.


This article from "ehealth" blog, declined reprint!

Java Learning notes----Thread 2

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.