{System.out.println("t1start");LockS"/> {System.out.println("t1start");LockS">

Home >Java >javaTutorial >How to use java's park method

How to use java's park method

WBOY
WBOYforward
2023-05-04 22:07:051630browse

Description

1. It belongs to the LockSupport class. LockSupport is a thread blocking tool class.

2. All methods are static. You can use park to block the thread, or use unpart to wake up the thread.

Example

public class Demo {
    public static void main(String[] args) {
        System.out.println("main start");
        Thread t1 = new Thread(() -> {
            System.out.println("t1 start");
            LockSupport.park();
            System.out.println("t1 end");
        });
        t1.start();
        LockSupport.unpark(t1);
        System.out.println("main end");
    }
}

The above is the detailed content of How to use java's park method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete