2

I noticed the size of each Runnable object is around 600KB. I am using the BlockingQueue with fix size of 10000. From the logging message, I saw all the 9864 objects had put into the queue. I did not see any the memory usage drastically increased. Should the queue be consuming 6GB (600KB x 9864) of memory?

1 Answers1

2
  1. First of all, BlockingQueue has only reference, so just BlockingQueue be consuming a very small memory.
  2. Secondly, important not how much objects in Queue, but how much unique objects (Queue may have a million references to one object).
  3. And at last, how you callculate size of each Runnable object? Also, every Runnable object has a lot of links to another objects, however some of this object can be shared between diferent Runnable object, so if size of the first Runnable objects is around 600KB, it isn't mean that other Runnable objects also will be such big.
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
  • Very reasonable explanation. I agree the only the reference will inserted to the BlockQueue, but each Runnable object still consumes memory spaces. Basically each Runnable is working on a row object (ORM framework), pull a row of data from DB, do some actions, and then put it back. A new object will be created when a row is pulled from DB, aren't they considered "unique ojbects"? As I mentioned in the comment above, I calculate the object by following http://stackoverflow.com/questions/9368764/calculate-size-of-object-in-java – user3842642 Dec 15 '15 at 00:18