weixin_41335120 2018-03-14 04:34 采纳率: 81.8%
浏览 922
已采纳

Balking 和 wait(), 什么时候用

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()。 所以我的问题是什么时候用这两个方法?

  • 写回答

2条回答

  • 自强不惜 2018-03-14 08:43
    关注

    有响应速度要求,或担心服务器卡死的用offer,其他情况用put。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页