Common member methods in multithreading

1. Common member methods

insert image description here
If no name is set for the thread, the thread also has a default name, format:
Thread-X (X serial number, starting from 0)
insert image description here

2. Create the name of the thread structure

Use the construction method to set the name of the thread.
insert image description here
When the JVM virtual machine starts, it will automatically start multiple threads, one of which is called the main thread. Its function is to call the main method and execute the code inside. In the past, all the code we wrote was actually running in the main thread.

static void sleep(long time) Let the thread sleep for the specified time, in milliseconds.
Details: Which thread executes this method, then which thread will stay here for the corresponding time; the staying time is related to the method parameters; when the time is up, the thread will automatically wake up and continue to execute other codes below
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44860226/article/details/132220023