Question: I'm new to Java and really need your help.

I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~ 

> 
> EDIT:I have checked, the queue first
>  stays at 100 or so, and after ten
>  seconds it starts to grow at 100 per
>  second, and crashes at 2000 or so.
>  Could it be possible that there is a
>  memory leak?
> 
> 
> 

My code (in a tight loop) is 

```
byte[] data = new byte[1024];
System.arraycopy(udpPacket.getData(), 0, data, 0, 1024);
queue.offer(data);

```

The heap is filled up too quickly, and I get an outofmemory exception. I guess the problem is that queue is made using a linked-list, and all the pointers must be saved in the heap.

I know a C version that does the same thing(using a buffer) but has much better performance, but because of deployment issues, we can only use Java.

Answer: 
If you receive 3000/sec but only process 100/sec sooner or later you will run out of memory.
May I suggest you use more threads to do the parsing?

Concerning the queue, have a look at [LinkedBlockingDeque](http://java.sun.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingDeque.html) and [LinkedBlockingQueue](http://java.sun.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingQueue.html). There are both high-performance thread-safe queue implementations.
Since data comes in 30 times faster than it is processed you may extend HeapSize using 

`java -Xms<initial heap size> -Xmx<maximum heap size>` if the transmission is finished before your memory is exhausted.

* Or as youself suggested dump the data to disc and process delayed.
* Otherwise you would have to optimze your parser