[concurrency-interest] Queue with interrupt

Gregg Wonderly gergg at cox.net
Tue May 23 16:49:22 EDT 2017


Many times I use a subclass of one of the queue implementations that I pass a signaling Object to.  That subclass overrides all methods that mutate the state of the queue, and the overriding methods have

	synchronized( lockObj ) {
		super.XXXXX();
		lockObj.notifyAll();
	}

in each of them so that they tell the lock waiters that something has changed.  The lack of a value to account for false signaling can be remedied by using a functional interface to signally instead of the literal Object signaling.

Then, I will also have a timer that fires to signal periodically to the same signal object, perhaps using a secondary signal type.

public interface ActionSignalHandler<E> {
	void QueueModified( SignallingQueue queue );
	void TimerFired( Timer which );
	void WorkCompleted( E work );
}

or some such.   This style of API provides the functionality I need generally when I have one or more queues interactive with one or more timers and have an environment such as Swing/JavaFX/AWT which needs a specific thread type against background tasks managing data values and the occasional ‘ticking’ task needed for progress indication or other change of state recognition or remote service integration.

Gregg

> On May 18, 2017, at 6:56 AM, Viktor Klang <viktor.klang at gmail.com> wrote:
> 
> OTOH, I'd rather avoid Blocking* whenever possible.
> 
> On Thu, May 18, 2017 at 1:43 PM, Chris Hegarty <chris.hegarty at oracle.com <mailto:chris.hegarty at oracle.com>> wrote:
> 
> > On 17 May 2017, at 10:29, David Holmes <davidcholmes at aapt.net.au <mailto:davidcholmes at aapt.net.au>> wrote:
> >
> > ...
> > If there are tasks in the queue then the worker is not waiting for new tasks to do - so you've changed your requirements. You would need a deque to allow sentinel tasks to be forced to the head of the queue.
> 
> I’ve always wished that we could somehow squeeze a sentinel into the
> implementation in order to provide a “CloseableBlockingQueue” with a
> blocking takeOrNull(), or similarly named, method. Rather than folk having
> to roll their own.
> 
> -Chris.
> 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu <mailto:Concurrency-interest at cs.oswego.edu>
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest <http://cs.oswego.edu/mailman/listinfo/concurrency-interest>
> 
> 
> 
> -- 
> Cheers,
>> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170523/4a921c52/attachment.html>


More information about the Concurrency-interest mailing list