# University # Java multithreading 01

Source: Internet
Author: User

* Java multithreading is basically implemented through the Thread class and runnable interface.

* Thread class Method

* Constructor

Thread ();

Thread (runnable); // used together with the interface, mainly to help the interface implement the START () method, because the runnable interface does not have the start Method

Thread (string name); // thread name

Thread (runnable, string name); // 4 = 2 + 3

* Other Methods

Start (); // start the thread

Interrupt ();//

Join (); // call other threads

Run (); // thread body

Sleep (long time); // sets the thread sleep time.

Wait (long time); // = sleep (long time)

Wait ();

Y (); // activates the thread, which is generally used with wait ().

Policyall ();

Isalive (); // check the thread status

Stop (); // force the thread to die

* The runnable interface has only one run () method. Therefore, interfaces are generally used together with tread objects.

 

* Thread Lifecycle

Create; // put the statements that require multi-thread execution into the run method.

Executable; // when the thread enables the START () method, it enters the executable state and executes the run () method.

Non-executable; // you can use the wait () and sleep () methods in the tread class to enter the "non-executable state ".

Dying; // when the run method is executed, the thread automatically disappears.

* Thread priority

The setpriority () method in the Thread class can be used to set the thread priority. The value range is 1 ~ 10. The default value is 5.

* Daemon

If all non-Background threads are finished, the background threads will also be terminated automatically.

Thread. setdaemon (Boolean on); // when the parameter is true, the thread is marked as the background thread.

Thread. isdaemon (); // determines whether the thread is 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.