码迷,mamicode.com
首页 > 编程语言 > 详细

3.1.7 线程阻塞工具类:LockSupport

时间:2018-02-07 11:58:10      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:oid   body   rac   support   current   err   public   join()   str   

package 第三章.线程阻塞工具LockSupport;

import java.util.concurrent.locks.LockSupport;

/**
* Created by zzq on 2018/2/2.
*/
public class LockSupportDemo {
public static Object u = new Object();
static ChangeObjectThread t1 = new ChangeObjectThread("t1");
static ChangeObjectThread t2 = new ChangeObjectThread("t2");

public static class ChangeObjectThread extends Thread {
public ChangeObjectThread(String name) {
super.setName(name);
}

public void run() {
synchronized (u) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("in " + getName());
LockSupport.park();
System.out.println("out " + getName());
}
}
}


public static void main(String args[]) throws InterruptedException {
t1.start();
Thread.sleep(3000);
t2.start();
LockSupport.unpark(t1);
LockSupport.unpark(t2);
t1.join();
t2.join();
}
}

3.1.7 线程阻塞工具类:LockSupport

标签:oid   body   rac   support   current   err   public   join()   str   

原文地址:https://www.cnblogs.com/anxbb/p/8425555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!