5
java | | 设计模式 同步模式 顺序控制 park & unpark
source link: https://benpaodewoniu.github.io/2022/12/20/java133/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
java | | 设计模式 同步模式 顺序控制 park & unpark
park & unpark
版本。
先输出 2
再输出 1
package com.redisc;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.locks.LockSupport;
@Slf4j(topic = "c.Run")
public class Run {
public static void main(String[] args) throws Exception {
Thread t1 = new Thread(() -> {
LockSupport.park();
log.debug("1");
});
t1.start();
new Thread(() -> {
log.debug("2");
LockSupport.unpark(t1);
}).start();
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK