• 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

JBoss with C3P0 Connection Pool Config/Usage

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Server configuration is not my specialty. I have an app I created that uses ejp3 over mysql. It was working fine except the database would disconnect after a period of inactivity. I decided to put in a connection pool that would manage this. C3P0 looked good and would be able to solve this problem.

Per the instruction on this site (http://www.mchange.com/projects/c3p0/#jboss-specific) I put the C3P0 jar in the jboss/server/default/lib dir. I created c3p0-service.xml per the site's instructions and then put it in the jboss/server/default/deploy dir. Restarting at this point causes no ill effect. I have C3P0 configured with AutomaticTestTable to ping periodically to keep the connection alive. I can see in my database that the table has been created. That tells me jboss found C3P0 and started it up.

Now this is where I get lost. Am I done? It seems to me that I now need to tell my old datasource (MySqlDS) to use C3P0 as the connection pool. Or do I now use the connection pool directly in the application instead of the old datasource (like in persistence.xml)?
 
Author
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, AFAIK, your datasource won't use the connection pool. You now have two, or perhaps three, datasources defined, which are accessible from different JNDI names.

1) Out of the box, there is a datasource called java:DefaultDS that is configured in deploy/hsqldb-ds.xml.
2) The config file you specified defines a java:PooledDS, which points to your database directly, hence the JDBC URL you defined.
3) You said that you had a java:MySqlDS defined as well.

Did you remove the default datasource (hsqldb-ds.xml)? If so, did you point all the existing services to point to your MySqlDS datasource? How did you configure your MySqlDS?

I'd suggest removing the MySqlDS (however you configured it) and the deploy/hsqldb-ds.xml. Then you can change the JNDI name on your c3p0 configuration to java:DefaultDS. Then you'll have to make all your code just call java:DefaultDS (or better yet you can use the ENC to create a local namespace for your app).

Side note: Those of you who have JBoss in Action, we talk about how to configure the default datasource in section 15.5.
 
Rusty Enisin
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey. Thanks for the reply. You confirmed what I feared; I have three independent datasources, none of which are accomplishing what I need.

I made the changes you suggested as best I understood. I now have three files related to the database connections:

1. hsqldb-ds.xml
2. c3p0-service.xml
3. jms/mysql-jdbc2-service.xml

Here is how each is configured.

hsqldb-ds.xml


c3po-service.xml


jms/mysql-jdbc2-service.xml


The server started without errors and the connection works in the application. The database was disconnecting after a period of no use. Now I will wait a while to see if it disconnects.
 
Rusty Enisin
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not confident that the DefaultDS is using c3p0 for the connection pool. Any ideas on how to test it? I am still getting this error after about 8 hours of inactivity:

java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2637)

It is entirely possible that c3p0 is working but is just not the proper solution for the problem. If so maybe I should create a new forum thread.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

after about 8 hours of inactivity



See if configuring the datasource with appropriate timeout values helps. More details here. By the way,



in your -ds.xml, looks incorrect to me. It should be set to x minutes, where x is the amount of time the an idle connection can be let to stay in the pool.
 
Javid Jamae
Author
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure you can configure two different datasources to point to DefaultDS the way you did.

Your hsqldb-ds.xml file and your c3po-service.xml files are both trying to configure datasources using the same JNDI name (java:DefaultDS). I would imagine that you would have an error somewhere in your logs complaining about binding to a JNDI name that already exists. So, the problem might be that c3p0 is not even binding to the JNDI name because its loading the hsqldb-ds.xml file first.

I would try deleting the hsqldb-ds.xml file altogether, thereby letting the c3p0-service.xml file bind the connection pool to that JNDI name.
 
reply
    Bookmark Topic Watch Topic
  • New Topic