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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题