4

I have need for a LinkedBlockingQueue but what I am passing primitives to it. My data rates for adding to the Queue are about 4ms or 256 data points per sec. The issue that I am having is the data starts to delay immediately on start but over time it seems the JIT makes this more efficient and it ends up real time. I am trying to figure out where I need to decrease the initial delay and one of them is the "newing" up a Float object from autoboxing on each insert in the Queue. Does anyone have a LinkedBlockingQueue using primitives?

Or is there something faster than LinkedBlockingQueue when you aren't sure of the sizes and using primitives?

JPM
  • 9,077
  • 13
  • 78
  • 137
  • 2
    256 data points / second seems very slow. I'd doubt if the time to add / remove to the queue is the issue here - It's more likely to be the rate at which you're producing / consuming it. – Adamski Oct 17 '11 at 17:16
  • you can copy the [source code](http://www.docjar.com/docs/api/java/util/concurrent/LinkedBlockingQueue.html) and change all the generic `E` to `float` – ratchet freak Oct 17 '11 at 17:18
  • The time it takes is around 1 micro-second. How much effort is it worth to save that much time. – Peter Lawrey Oct 17 '11 at 17:56
  • On a fast computer its about 1 microsecond, I am actually putting this on an android phone so it ends up being about 1ms per initially then it eventually becomes 10 microseconds. – JPM Oct 17 '11 at 18:14
  • why do u have to use blocking queue? if you use a regular queue, does it perform better? as far as i can tell you, using a primitive, your queue will be boxing the primitive in to a Wrapper object. – DarthVader Oct 17 '11 at 18:15
  • Using a LinkedBlockingQueue because I am passing data between threads and want to do so in a FIFO. – JPM Oct 17 '11 at 18:28

1 Answers1

1

Though your data isn't really large enough to warrant better data structures, the Fastutil library is exactly what you're looking for. It's collections that are fast and low memory footprint, and they have versions for each Java primitive.

They don't have implementations for blocking, but you should be able to extend their classes to add their functionality.

Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77