java multithreading learning (1)

Process: The execution process of the program, holding the carrier of resources (shared memory, shared files) and threads.

Thread: Thread is the smallest execution unit in the system. There are multiple threads in the same process, and threads share the resources of the process.

There are two common methods of java multi-threading, namely by inheriting the class class of Thread and by implementing the interface (interface) of Runnable. There is a common method run() in the Thread class and the Runnable interface, and the run() method contains the specific code executed by the thread.

Common methods in the Thread class:

category f method signature Introduction
thread creation Thread()  
Thread(String name)  
Thread(Runnable target)  
Thread(Runnable target,String name)  
thread method void start() start thread
static void sleep(long millis) millis refers to milliseconds thread sleep
static void sleep(long millis,int nanos)
void join() Make other threads wait for the current thread to terminate
void join(long millis ,int nanos)
void join(long  millis,int nanos)
static void yield() Causes the currently running thread to release processor resources
get thread reference sstatic Thread currentThread() Returns a reference to the currently running thread

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325167077&siteId=291194637