Prev Next

Java / Concurrent collections

Explain SynchronousQueue in Java concurrent collections.

The SynchronousQueue class implements the BlockingQueue interface introduced in Java 1.5.

SynchronousQueue is a blocking queue in which each insert operation must wait for a corresponding remove operation by another thread, and vice versa. A synchronous queue does not have any internal capacity.

The peek operation cannot be performed at a synchronous queue because an element is only present when you try to remove it; you cannot insert an element (using any method) unless another thread is trying to remove it; you cannot iterate as there is nothing to iterate. The head of the queue is the element that the first queued inserting thread is trying to add to the queue; if there is no such queued thread then no element is available for removal and poll() will return null. This queue does not permit null elements.

This class supports an optional fairness policy for ordering waiting producer and consumer threads. A queue constructed with fairness set to true grants threads access in FIFO order.

They are well suited for handoff designs, in which an object running in one thread must sync up with an object running in another thread in order to hand it some information, event, or task.

It's right time to invest in Cryptocurrencies Dogecoin! Earn free bitcoins up to $250 now by signing up.

Earn bitcoins upto $250 (free), invest in other Cryptocurrencies when you signup with blockfi. Use the referral link: Signup now and earn!

Using BlockFi, don't just buy crypto - start earning on it. Open an interest account with up to 8.6% APY, trade currencies, or borrow money without selling your assets.


Join CoinBase! We'll both receive $10 in free Bitcoin when they buy or sell their first $100 on Coinbase! Available in India also. Use the referral Join coinbase!


Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

Explain concurrent collection API. List some of the concurrency collection interfaces. Explain BlockingQueue in Java concurrent collections. I have one List of Map like - List> list = new ArrayList>(); I want to return the Key if any value passed by user is equal to the value present in Map using Java 8 . One way to doing is - Map data = new HashMap<>(); list.stream().forEach(map -> { data.putAll(map.entrySet().stream() .collect(Collectors.toMap(entry -> entry.getKey(), entry -> (String) entry.getValue()))); }); String result = data.entrySet().stream() .filter(map -> "def".equals(map.getValue())) .map(map -> map.getKey()) .collect(Collectors.joining()); But I want to do to it without using collect(). Please help me on that. Thank you. What are the 4 forms of BlockingQueue methods? Does BlockingQueue supports removal of arbitrary element? Is BlockingQueue implementations are thread safe? Define poison pill or object in Java collections. What does drainDo method in BlockingQueue do? List the implementations of BlockingQueue. Does BlockingQueue allow null elements? Explain ArrayBlockingQueue in Java concurrency collections. What is Bounded buffer? Explain DelayQueue in Java Concurrent collections. Explain LinkedBlockingQueue in Java concurrent collections. Explain PriorityBlockingQueue in Java concurrency collections. Difference between ArrayBlockingQueue and LinkedBlockingQueue. Difference between synchronizedMap and ConcurrentHashMap in Java. Why does ConcurrentHashMap does not allow null key or values? Can we use ConcurrentHashMap in a single threaded application? Difference between Hashtable and ConcurrentHashMap in Java. What is High throughput computing? Difference between ConcurrentHashMap and HashMap. Explain SynchronousQueue in Java concurrent collections. What is shutdown hook in Java Thread? Difference between Runnable and Callable in Java Thread. How to stop a running thread in Java? Why is Thread.stop deprecated? Why are Thread.suspend and Thread.resume deprecated? Difference between findMonitorDeadlockedThreads and findDeadlockedThreads in Java ThreadMXBean. Define ownable synchronizer in Java thread. Explain ThreadMXBean in Java. Design patterns used in Java multithreading. Is final field initialized in constructor thread-safe? Difference between submit and execute method with ThreadPoolExecutor. If a synchronized method calls another non-synchronized method, is there a lock on the non-synchronized method? What is defensive copying in Java? What is Program counter? What is Java Shutdown Hook? When to use FixedThreadPool in Java? Advantages of immutable objects in multithreaded environment. Difference between LinkedBlockingQueue and ConcurrentLinkedQueue in Java. How to make sure the overrided method is also synchronized in Java? Explain ConcurrentHashMap in Java. Is ConcurrentHashMap thread-safe in Java? Can multiple threads read from ConcurrentHashMap at same time? How ConcurrentHashMap works internally? How does ConcurrentHashMap achieve thread-safety? How to atomically update a value in ConcurrentHashMap? Is Iterator of ConcurrentHashMap fail-safe or fail-fast? What is Spliterator in Java 8? What is reactive streaming in Java9? Why reactive programming is preferred? Explain stream pipelining in Java 8. How does CopyOnWriteArrayList internally works in Java? Difference between ConcurrentSkipListMap and ConcurrentHashMap.
Show more question and Answers...

Java Serialization

Comments & Discussions