The BlockingQueue interface in Java includes an operation, offer(),
that uses balking to add an element to the end of the queue if possible, and
another operation, put(), that uses guarded suspension to add an element to
the end of the queue. Under which circumstances would you use one of these
operations instead of the other, and why?
题目大概是问什么时候用 offer() 什么时候用 put(), 因为他们的implemention其实不一样,offer 是用 balking,就是如果出错就忽视, 或者throw exception。 put 就是如果满了就call wait()。 所以我的问题是什么时候用这两个方法?
Balking 和 wait(), 什么时候用
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答
- 自强不惜 2018-03-14 08:43关注
有响应速度要求,或担心服务器卡死的用offer,其他情况用put。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报