Getting Started with Java-multithreading (ii)

Source: Internet
Author: User

Getting Started with Java-multithreading (ii) The state of the thread

To implement multi-threading, a new thread object must be created in the main thread. Any thread typically has 5 states.

  

    1. Create state: After a thread object is created with a construction method, the new thread is in that state. The corresponding memory space and other resources and other resources are already available.
    2. ready state: thread queues into thread queue, waiting for CPU service.
    3. Running Status: CPU processing, the run () method is called automatically.
    4. blocking state: is temporarily suspended during execution. The reasons are: Artificial suspend, CPU decision, sleep (), suspend (), wait () and other methods. Only if the cause of the blocking is eliminated, the thread can go into a ready state and wait for it to run.
    5. dead State: the call to stop () method or the run () method execution end is in the dead state.
Related methods for threading operations
Serial number Method name Type Describe
1 Public Thread (Runnable target) Structure Receives the Runnable interface subclass object, instantiates the thread object
2 PUBLC Thread (Runnable target,string name) Structure Receives the Runnable interface subclass object, instantiates the thread object, and sets the threading name
3 PUBLC Thread (String name) Structure Instantiate the thread object and set the name of the threads
4 public static Thread CurrentThread () Ordinary Returns the process currently being executed
5 Public final String GetName () Ordinary Returns the name of the thread
6 public boolean isinterrupted () Ordinary Returns whether the current thread has been interrupted
7 Public final isAlive ()//Decide whether to start Ordinary Returns whether the thread is getting
8 Public final void join () throws interrupted Exception//Enforcement Ordinary Waiting for thread to die
9 public void Run () Ordinary Start thread
10 Public final void SetName (String name) Ordinary Set Thread name
11 Public final void setpriority (int newprioruty) Ordinary Set the priority level
12 public static void sleep (long Millis) throws interruptedexception//thread hibernation Ordinary Causes the currently executing thread to hibernate milllis seconds
13 public void Start () Ordinary Start thread Execution
14 Public String toString () Ordinary Returns a String representing a thread
15 public static void yield ()//comity of Threads Ordinary Pauses the currently executing thread
16 Public final void Setdeamon (Boolean on)//Background thread Ordinary Set a thread to run in the background

Getting Started with Java-multithreading (ii)

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.