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"