Thread-safe
transfer (T t) content delivery directly to a consumer, if the consumer will not clog
public static void main(String[] args) throws InterruptedException {
TransferQueue<String> tq = new LinkedTransferQueue<>();
tq.transfer("test");
new Thread(()->{
try {
Thread.sleep(500);
System.out.println(tq.poll());
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
The above code will be blocked.
tryTransfer (T t, long long, TimeUnit unit) to try a certain time, if not consumers, returns false.