How can I check whether a RabbitMQ message queue exists or not?

Don’t bother checking. queue.declare is an idempotent operation. So, if you run it once, twice, N times, the result will still be the same. If you want to ensure that the queue exists, just declare it before using it. Make sure you declare it with the same durability, exclusivity, auto-deleted-ness every time, otherwise you’ll get …

Read more

Java Collections (LIFO Structure)

There’s actually a Stack class: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Stack.html If you don’t want to use that, the LinkedList class (http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html) has addFirst and addLast and removeFirst and removeLast methods, making it perfect for use as a stack or queue class.

How do you pass a Queue reference to a function managed by pool.map_async()?

The following code seems to work: import multiprocessing, time def task(args): count = args[0] queue = args[1] for i in xrange(count): queue.put(“%d mississippi” % i) return “Done” def main(): manager = multiprocessing.Manager() q = manager.Queue() pool = multiprocessing.Pool() result = pool.map_async(task, [(x, q) for x in range(10)]) time.sleep(1) while not q.empty(): print q.get() print result.get() …

Read more

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