java BlockingQueue does not have a blocking peek?

You could use a LinkedBlockingDeque and physically remove the item from the queue (using takeLast()) but replace it again at the end of the queue if processing fails using putLast(E e). Meanwhile your “producers” would add elements to the front of the queue using putFirst(E e). You could always encapsulate this behaviour within your own … Read more

What is the Difference between ArrayBlockingQueue and LinkedBlockingQueue

ArrayBlockingQueue is backed by an array that size will never change after creation. Setting the capacity to Integer.MAX_VALUE would create a big array with high costs in space. ArrayBlockingQueue is always bounded. LinkedBlockingQueue creates nodes dynamically until the capacity is reached. This is by default Integer.MAX_VALUE. Using such a big capacity has no extra costs … Read more

ExecutorService vs ThreadPoolExecutor using LinkedBlockingQueue

Here is the source of Executors.newFixedThreadPool: public static ExecutorService newFixedThreadPool(int nThreads) { return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); } It internally uses ThreadPoolExecutor class with default configuration as you can see above. Now there are scenarios where default configuration is not suitable say instead of LinkedBlockingQueue a priority queue needs to be used … Read more

Are there any concurrent containers in C++11? [closed]

According to Diego Dagum from Microsoft’s Visual C++ Team: A recurrent question (well, one of the many) is about STL containers and whether they are thread safe. Taking Stephan’s words here, the reality is that they aren’t, not as a bug but as a feature: having every member function of every STL container acquiring an … Read more

When should I use SynchronousQueue over LinkedBlockingQueue

the SynchronousQueue is more of a handoff, whereas the LinkedBlockingQueue just allows a single element. The difference being that the put() call to a SynchronousQueue will not return until there is a corresponding take() call, but with a LinkedBlockingQueue of size 1, the put() call (to an empty queue) will return immediately. I can’t say … Read more

Blocking queue and multi-threaded consumer, how to know when to stop

You should continue to take() from the queue. You can use a poison pill to tell the worker to stop. For example: private final Object POISON_PILL = new Object(); @Override public void run() { //worker loop keeps taking en element from the queue as long as the producer is still running or as //long as … Read more

When to prefer LinkedBlockingQueue over ArrayBlockingQueue?

Boris the Spider has already outlined the most visible difference between ArrayBlockingQueue and LinkedBlockingQueue – the former is always bounded, while the latter can be unbounded. So in case you need an unbounded blocking queue, LinkedBlockingQueue or a LinkedTransferQueue used as a BlockingQueue are your best bets from the java.util.concurrent toolbox. But let’s say you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)