Scientist Scientist - 1 year ago 227
Java Question

LinkedBlockingQueue put vs offer

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

I need to know which one is better

in case of linked blocking queue.

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.

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

Answer Source

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.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download