Common methods for threading state transitions and threading control in Java

Source: Internet
Author: User

Thread state transitions in Java:

  

Note: Start execution immediately after start, just ready (the CPU may be running other threads).

"Note": Only after the CPU is dispatched, the thread will start executing, and when the CPU is allocated to your time slice, and back to the ready state, continue to wait in line.

The basic method of threading control:

  IsAlive (): Determine if the thread is still alive, start, and before the termination is alive;

GetPriority (): Gets the priority number of the thread;

SetPriority (): Sets the priority number of the thread (the thread roommate priority level);

Thread.Sleep (): Specifies the number of milliseconds to sleep on the current thread;

Join (): Calls the method of a thread, merges the current thread with the thread, waits for the thread to end, and then resumes the current thread's running state (for example, thread A's join () method is called in Threads B until thread a finishes executing, and then thread B is resumed);

Yield (): The current thread out of the CPU, into a ready state, waiting for the CPU to dispatch again;

Wait (): The current thread enters the object's wait pool;

Notify ()/notifyall (): Wakes up one/all waiting threads in the wait pool of the object.

1. Sleep () Method:

① can invoke the static method of Thread:

public static void sleep(long Millis) throws Interruptedexception: Allows the currently executing thread to hibernate (suspend execution) within the specified number of milliseconds. This operation is affected by the accuracy and accuracy of the system timer and scheduler, and the thread does not lose ownership of any monitors.

② because it is a static method, sleep () can be called directly by the class name.

Thread.Sleep (...);

Common methods for threading state transitions and threading control in Java

Related Article

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.