Java BlockingQueue with batching?

前端 未结 5 1557
有刺的猬
有刺的猬 2021-01-01 16:00

I am interested in a data structure identical to the Java BlockingQueue, with the exception that it must be able to batch objects in the queue. In other words, I would like

5条回答
  •  粉色の甜心
    2021-01-01 16:30

    I recently developed this utility that batch BlockingQueue elements using a flushing timeout if queue elements doesn't reach the batch size. It also supports fanOut pattern using multiple instances to elaborate the same set of data:

    // Instantiate the registry
    FQueueRegistry registry = new FQueueRegistry();
    
    // Build FQueue consumer
    registry.buildFQueue(String.class)
                    .batch()
                    .withChunkSize(5)
                    .withFlushTimeout(1)
                    .withFlushTimeUnit(TimeUnit.SECONDS)
                    .done()
                    .consume(() -> (broadcaster, elms) -> System.out.println("elms batched are: "+elms.size()));
    
    // Push data into queue
    for(int i = 0; i < 10; i++){
            registry.sendBroadcast("Sample"+i);
    }
    

    More info here!

    https://github.com/fulmicotone/io.fulmicotone.fqueue

提交回复
热议问题