Thread control

1、 Thread sleep

Method used: public static void sleep (long millis): let the executing thread sleep for millis

Public static void sleep (long millis, int nanos): sleep the executing thread for millis plus nanos

2、 Thread join

Method used: public void join(): wait for the thread to terminate

When this method is called on a thread object, other threads can execute only after the thread has finished executing.

3、 Thread comity

Method used: public static void yield(): pause the currently executing thread and execute other threads

4、 Daemon thread

Method used: public void setdaemon (Boolean on): mark the thread as a daemon or user thread. If on is true, mark it as a daemon. The daemon thread will be forced to end after the end of the user thread, regardless of whether it has finished running or not. It can be understood that the daemon thread guards and serves the user thread.

5、 Interrupt thread

Method used: public void interrupt(): interrupt the thread. If a thread is blocked in calling the wait (), wait (long) or wait (long, int) methods of the object class, or the join (), join (long, int), sleep (long) \ sleep (long, int) methods of the class, its interrupt state is cleared and it will also receive an interruptexception.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>