Skip to content

a Blocking Queue to be used in a multi threaded environment which keeps the order within the partition

License

Notifications You must be signed in to change notification settings

mobility-university/partitioned-blocking-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build

PartitionedBlockingQueue

a Blocking Queue to be used in a multi threaded environment which keeps the order within the partition.

Motivation

when reading from one and writing to another queue in a multi threaded java programm, then there was no simple solution to achieve this when the data needed to be kept in the order for some partitions.

Usage

@ThreadSafe
class Processor {
    private PartitionedBlockingQueue<YourPartitionKey, YourValue> queue;

    public Processor() {
        int numberOfPartitions = 10;
        this.queue = new PartitionedBlockingQueue(numberOfPartitions);
    }

    public void work(YourValue value) {
        YourPartitionKey key = toPartitionKey(value);
        YourValue toProcess = this.queue.acquire(key, value);
        try {
            // here your timely expansive operation with "toProcess"
        } finally {
            // release the partition to be able that the next thing is processed
            this.queue.release(key);
        }
    }

    private YourPartitionKey toPartitionKey(YourValue value) {
        return null; // your code
    }
}

Artifact

<dependency>
  <groupId>io.github.mobility-university</groupId>
  <artifactId>partitioned-blocking-queue</artifactId>
  <version>0.1</version>
</dependency>

About

a Blocking Queue to be used in a multi threaded environment which keeps the order within the partition

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published