1. 程式人生 > >Thread wait notify用法

Thread wait notify用法

if (jobThread == null) {
			jobThread = new Thread(new OrderJobRunnable());
			jobThread.start();
		} else {
			synchronized (jobThread) {
				jobThread.notify();
			}
		}
	private class OrderJobRunnable implements Runnable {
		@Override
		public void run() {
			// /如果不為空
			while (true) {
				if (unPayOrders.isEmpty()) {
					try {
						synchronized (this) {
							wait();
						}
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				} else {

					 
				} // else end
			} // while end
		}
	}