• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I use a ConnectionPool for non-JEE applications?

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In another thread, @bear said that one should always use a ConnectionPool. I can see the good reasons for that. But when I write a simple Java application, without all the complexity of servlets, JEE, containers, etc. there are no ConnectionPool support.

How do I start?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check out c3p0 or BoneCP
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apache's BasicDataSource implements a connection pool
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides choosing a connection pool, you'll need something which runs at program startup to start the pool running. I expect each pool implementation has something like that which should hopefully be documented. And you'll have to configure the pool. And you'll have to change your application's code (if it's already written) to get its connections from the pool rather then directly from the JDBC driver.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill Gorder wrote:check out c3p0 or BoneCP

How in the world can one google for c3p0 and not get the droid you are looking for?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O != 0
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, when I said "always", I actually meant in web apps. When you say non-JEE, do you mean Swing, or do you mean a single-threaded console application? Perhaps a connection pool may be overkill in a single-threaded console app, where you'll only need to worry about one connection at a time.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:And, when I said "always", I actually meant in web apps. When you say non-JEE, do you mean Swing, or do you mean a single-threaded console application? Perhaps a connection pool may be overkill in a single-threaded console app, where you'll only need to worry about one connection at a time.


I tend to write a lot of utility programs, they will beat on the DBMS, read gigabytes of data, say for loading a complex tree of objects. If I'm going to use them, they are simple shell program driven. If I expect others, I'll use Swing and stick up a simple GUI.

But behind the startup facade, I use huge libraries of business logic that are also used in webapi with tomcat and lots of servlet stuff. Rarely is a "simple shell program" not using multiple threads, daemons, etc.

So the answer is "yes"

I want the same code to work with ten lines of Java from a shell, and tens of thousands of lines in a JEE container.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was last year, I think, that I converted the Swing app which is my decade-long project to use a connection pool. However I didn't use one of the connection pools which you usually see recommended for web applications, because that seemed rather like getting a 40-foot flatbed truck to bring my groceries home from the store.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic