201671010131 2016-2017-2 "Java Programming"

Source: Internet
Author: User
Tags thread class

Startup and creation of threads
Thread Class (Java.lang.Thread Class)
In the Java language, the thread class represents threads, and all thread objects must be instances of the thread class or its subclasses. The role of each thread is to accomplish a certain task, in fact, to execute a program flow, also known as a sequential execution of code, Java uses the Run method to encapsulate such a program flow.

Inherit the thread class to create and start threads
1. Define a subclass of the thread class and override the Run method of the class, which represents the task that the thread needs to accomplish, and the Run method is also known as the thread execution body.
2. Create an instance of the thread class subclass, which is the object that created the threads.
3. Use the Start method of the thread object to start the thread.

Start () method
Causes the thread to start executing, and the Java Virtual machine calls the thread's Run method.
GetName () method
Returns the name of the thread
SetName (String name) method
Modify the name of the thread
Interrupt ();
Break Thread in
Sleep (long Millis);
Sleeps the currently executing thread within the specified millisecond. There are serial threads and synchronization threads.

Synchronizing code blocks:
Synchronized (same data) {} The same data: N threads access one data at the same time.

201671010131 2016-2017-2 "Java Programming"

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.