aspose file tools*
The moose likes Performance and the fly likes apache commons pool: out of memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "apache commons pool: out of memory" Watch "apache commons pool: out of memory" New topic
Author

apache commons pool: out of memory

Will Lee
Ranch Hand

Joined: Mar 16, 2005
Posts: 58
I'm implementing a connection pool using Apache commons pool:
the connection factory implements the PoolableObjectFactory, and the connection pool extends GenericObjectPool with such setting (just make up the number here):
setMaxIdle(10);
setMaxActive(10);
setWhenExhaustedAction(grow, WhenExhaustedAction);
setTestOnBorrow(true);
setTimeBetweenEvictionRunsMillis(1000);
setMinEvictableIdleTimeMillis(10000);

when object is destoryed or validation failed (in factory class), I set the object reference to null, hoping garbage collection will happen.

I set JVM heap memory very low (only 16MB), then try to get a lot of connections by pool.borrowObject(), and then return them to the pool:
MyConnection conn = pool.borrowObject();
// do something ....
pool.returnObject(conn);
conn = null;

Most of the time the total active and idle connection is low (only at one moment it reaches 100 objects) during my memory leak test. However it seems the connection objects were not garbage collected and it quickly caused OutOfmemory exception.

Any advice? how come the connection objects that are set to null were not GCed? How to solve this issue? using SoftReferenceObjectPool? using weakRefObj?

Thanks!

SCJP 1.4, SCWCD, SCDJWS
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Are you sure that the outofmemory is caused by the connection objects only. It may be that other objects are getting piled up.

Can't say much without seeing more of your code.


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

Will Lee wrote:

Any advice? how come the connection objects that are set to null were not GCed?



Because the "Connection objects" weren't set to null, the Connection object references were set to null. The objects were returned to the pool, and the poolmanager would have to remove them from its resource list as well before they were truly eligible for garbage collection.

Personally, as long as I was using the apache commons pool, I'd probably use the apache commons dbcp as well, since it already provides a connection pooler built on commons pool and it supplies J2EE-compliant datasource services - including wrapping the connections, so that you can return the connection to the pool using the close() method.

There's also 1 or 2 other pre-debugged connection pool managers in open source, for that matter.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: apache commons pool: out of memory
 
Similar Threads
Connection Pooling (Performance Tuning)
how to use JDBC Connection Pools in a standalone application?
Garbage collection of strings ?
Connection Leaks
Apache Commons DBCP connection object problem