本文介绍了LinkedBlockingQueue put vs offer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接阻塞队列,我在其中执行插入和删除操作。

I have a linked blocking queue in which I am performing insertion and removal operations.

我需要知道哪一个更好 put 或 offer

I need to know which one is better put or offer in case of linked blocking queue.

性能参数是CPU利用率,内存和整体吞吐量。

Performance parameters are CPU utilization, memory and overall throughput.

应用程序使用是实时系统,其中可以有多个传入请求和更少的线程来处理我们需要在队列中插入元素的位置。

Application usage is Real time system where there can be multiple incoming requests and less threads to handle where we will need to insert element in queue.

我阅读了Java文档的put和offer,内部应用程序没有太大区别。

I read Java docs of put and offer there was not much difference in internal application.

推荐答案

实际上,你无法比较这两者之间的表现,报价方法只是提供给队列,它不等待或等待指定的时间,但 put 方法等待无限长,直到空间可用,所以它们的用法是不同的。

Actually, you can't compare performance between these two, the offer method is to just offer to the queue and it does not wait or waits for the time specified, but the put method waits infinitely long until space is available, so their usage is different.

使用放在哪里你买不起物品,记住它会阻止你调用堆栈,否则使用 offer

Use put where you cannot afford to loose an item, keeping in mind it will hold up your call stack, otherwise use offer.

这篇关于LinkedBlockingQueue put vs offer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 18:03