java - Poison a blocking queue when the queue type contains a generic -
i have type, mytype<t> contains generic type t. have blocking queue of type blockingqueue<mytype<t>>. send "end-of-stream" markers queue, i.e. poison pills, issue cannot instantiated poison pill because of generic type. there way around this?
you should able create one.
class mytype<t> { private blockingqueue<mytype<t>> q = new arrayblockingqueue<>(10); // poison pill signal end of queue. public static final mytype<?> pill = new mytype<>(); /** * special private constructor pill creation. */ private mytype() { } public boolean queueclosed() { return q.peek() == pill; } } if have own constructors add private constructor no parameters.
Comments
Post a Comment