简体   繁体   中英

Multiplexing Java's LinkedBlockingQueue

是否有一个很好的模式可以将多个Java的LinkedBlockingQueue实例复用到一个具有(高效)阻塞等待语义的实例上?

Is there a nice pattern for multiplexing multiple of Java's LinkedBlockingQueue instances onto one with the semantics of (efficient) blocking wait?

I'd have one thread per input LinkedBlockingQueue each calling take() and then putting the elements into the shared output LinkedBlockingQueue .

Something like:

public void run() {
    while (!Thread.currentThread().isInterrupted()) {
        try {
            outputQueue.put(inputQueue.take());
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            return;
        }
    }
}

Not sure what else to say about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM