`

线程处理队列

 
阅读更多
// param:phone-msg
	public static LinkedBlockingQueue<JSONObject> msgDataQueue = new LinkedBlockingQueue<JSONObject>();
	// 启动线程
	class MsgQueueThread extends Thread {
		@Override
		public void run() {
			while (true) {
				try {
					JSONObject json = msgDataQueue.take();
					sendMsg(json.getString("phone"), "sys_notice",
							json.getString("msg"));
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}


take()阻塞线程,当msgDataQueue 中有值时,则线程继续.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics