• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check out c3p0 or BoneCP
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apache's BasicDataSource implements a connection pool
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O != 0
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic