Thread wait notify用法

来源:互联网 发布:虚拟windows系统 编辑:程序博客网 时间:2024/05/01 22:37
if (jobThread == null) {jobThread = new Thread(new OrderJobRunnable());jobThread.start();} else {synchronized (jobThread) {jobThread.notify();}}


private class OrderJobRunnable implements Runnable {@Overridepublic void run() {// /如果不为空while (true) {if (unPayOrders.isEmpty()) {try {synchronized (this) {wait();}} catch (InterruptedException e) {e.printStackTrace();}} else { } // else end} // while end}}



0 0
原创粉丝点击