Which Java Queue is best for recursive image processing?

To build on @dipen-soni answer, if you plan to scale your image processing with multiple threads, you’ll need a thread-safe Java queue implementation.

Use ConcurrentLinkedQueue (Thread-Safe Option) For parallelized image processing, ConcurrentLinkedQueue is a winner. It offers lock-free, thread-safe operations, making it perfect for multi-threaded environments. It still maintains O(1) enqueue and dequeue efficiency, just like LinkedList.

:fire: Why ConcurrentLinkedQueue?

  • Non-blocking and thread-safe.
  • Faster in multi-threaded environments.
  • No locks, ensuring smooth performance.

Code Example:

Queue<Pixel> pixelQueue = new ConcurrentLinkedQueue<>();  

pixelQueue.add(new Pixel(10, 10));  // Push  
Pixel nextPixel = pixelQueue.poll();  // Pop