I have an application that generates millions of events and sends those events to a server and receives Futures for each event. In order to prevent the application from running out of memory, I put those Futures in a ArrayBlockingQueue
and that queue is processed by another thread.
My application sends those events faster than it can process those Futures and hence the application slows down quite a bit.
What is the best way to handle these Futures?
Without knowing what are your needs in the application it is hard to suggest performance tip.
Maybe you could speed up the consuming if you use more than one thread through a fixed thread pool with a carefully chosen max thread number (an unlimited thread executor would slow down your application also).
Another way to rethink the structure of the application. E.g. During consuming the futures is there any process which can be refactored to do later.
Some code example would help to give more specific advice.