Code example for PriorityBlockingQueue

0
	// Boolean to track if disposed 
	private Boolean dispatcherDisposed = false;
	 
	public ProxyMessageDispatcher(String THREAD_NAME, Comparator<messageType> messageComparator, 
			IDispatchingStrategy<messageType> strategy) {
		_queue = new PriorityBlockingQueue<messageType>(10, messageComparator);
		 
		_strategy = strategy;
		 
		// Create dispatching thread 
		_messageDispatchingThread = new Thread(new Runnable() {public void run(){handleMessages();}});
		_messageDispatchingThread.setName(THREAD_NAME);
		_messageDispatchingThread.setDaemon(true);
		_messageDispatchingThread.start();
	} 
	 
	public void dispose() { 
		dispatcherDisposed = true;
		 
		if(_messageDispatchingThread != null) {
			_messageDispatchingThread.interrupt();