Elegantly implementing queue length indicators to ExecutorServices

There is a more direct way: ThreadPoolExecutor executor = new ThreadPoolExecutor( 1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>() ); // add jobs // … int size = executor.getQueue().size(); This is directly copied from Executors.newSingleThreadExecutor in JDK 1.6. The LinkedBlockingQueue that is passed to the constructor is actually the very object that you will get back from … Read more

Job queue as SQL table with multiple consumers (PostgreSQL)

I use postgres for a FIFO queue as well. I originally used ACCESS EXCLUSIVE, which yields correct results in high concurrency, but has the unfortunate effect of being mutually exclusive with pg_dump, which acquires a ACCESS SHARE lock during its execution. This causes my next() function to lock for a very long time (the duration … Read more

How can I check if a Queue is empty?

Assuming you mean Queue<T> you could just use: if (queue.Count != 0) But why bother? Just iterate over it anyway, and if it’s empty you’ll never get into the body: Queue<string> queue = new Queue<string>(); // It’s fine to use foreach… foreach (string x in queue) { // We just won’t get in here… }

Difference between Laravel queued event listeners vs jobs

Good question, I will begin by how laravel docs explains it Events : Laravel’s events provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application. Events serve as a great way to decouple various aspects of your application, since a single event can have multiple listeners … Read more

awaitable Task based queue

I don’t know of a lock-free solution, but you can take a look at the new Dataflow library, part of the Async CTP. A simple BufferBlock<T> should suffice, e.g.: BufferBlock<int> buffer = new BufferBlock<int>(); Production and consumption are most easily done via extension methods on the dataflow block types. Production is as simple as: buffer.Post(13); … Read more