java - How do I give priority to Consumers when using a LinkedBlockingQueue? -


i using linkedblockingqueue producer/consumer pattern buffer tasks. add tasks queue use method producers: queue.put(object); take task form queue use consumers: queue.take(object);

i found in java api both these methods block until queue becomes available. problem is: know fact there more producers of tasks in system consumers. , tasks need processed. need consumers, when blocked, have priority on producers queue.

is way without changing methods of linkedblockingqueue much?

linkedblockingqueue uses 2 reenterantlocks lock.

private final reentrantlock putlock = new reentrantlock();

private final reentrantlock takelock = new reentrantlock();

since both locks seperate , put , take aquires seperate locks carrying out operating blocking 1 operation not impact other operation.

cheers !!


Comments