Reputation: 2561
Anyone can help me to write an algorithm for object pooling. I am very new in J2EE and i need object pooling for database connection. So please help out. Thanks
Upvotes: 1
Views: 664
Reputation: 38615
I am very new in J2EE and i need object pooling for database connection.
The whole point of the Java EE platform is to relief the developper form writing such infrastructure code, and focus on the business logic. Whether the platform succeeds at this or not, is another debate, but it's a least the vision.
Given that you are new to it, I would strongly suggest that you spend some time to get an better understanding of what the platform provide, and what's the vision behind it.
Connection pooling is just one thing, the platform provide specific ways to deal with configuration, security, deployment, monitoring, etc.
Regarding connection pooling specifically, see What is best approach for connection pooling?
Upvotes: 2
Reputation: 118661
All of the major Servlet and Java EE containers come with their own Connection pooling implementations, available through JNDI. Check the documentation with your container.
Upvotes: 2
Reputation: 298898
Rather than writing your own Object pool you should probably use an existing solution, e.g.
Commons Pool: http://commons.apache.org/pool (for object pools in general)
or
Commons DBCP: http://commons.apache.org/dbcp (for db connection pools)
Upvotes: 2
Reputation: 7496
Database connection pooling is a tough problem and is difficult to get it right. However, you could use several open source solutions which offer Connection Pooling. You can consider using C3P0 or Apache DBCP to get the connection pooling you desire.
In case you are working in an application server environment such as Glassfish, Weblogic or Jboss, connection pooling is provided by the application server itself. You need to create a datasource and enable pooling that you wish to have.
Upvotes: 3