-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: why openSession is blocked under mulit thread env...
PostPosted: Tue Jan 02, 2007 10:27 pm 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.2

Name and version of the database you are using:oracle 8.1.7

first, sorry for my poor english..

I build 7 java class file. also, they run same jvm. one main class calls other classes every time very oftenly and concurrently. so, I use jdk 1.5 thread pool and run 5 thread.
each of them use below code whenever they need it.

Code:
try{
    sess = HibernateUtil.getSessionFactory().openSession();
    tx = sess.beginTransaction();
    .......
    .......
} catch( ....){
.....
} finally{
//sess.close();
}


HibernateUtil class code like this..

Code:
public class HibernateUtil {

    private static final SessionFactory sf1;
//    private static final SessionFactory sf2;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sf1= new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
//            sf2= new Configuration().configure("hibernate2.cfg.xml").buildSessionFactory();

        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sf1;
    }

//    public static SessionFactory getMapSessionFactory() {
//        return sf2;
//    }


}


every time program execute. only one class code blocking thread execution and whole program blocked.

so, I insert debug code like this.
Code:
try{
    logger.debug("blablabla");
    sess = HibernateUtil.getSessionFactory().openSession();
    tx = sess.beginTransaction();
    logger.debug("ahahaha");
    .......
    .......
} catch( ....){
.....
} finally{
.....
}


whole program blocked after "blablabla"...

It happend every time only one class code..

I can't catch exact blocking time even every time program executing same routine.

I will appreciate take whatever your advice or tip or others..

added here jvm dump(this app is my first thread app. so, I newbie multi thread..and programming...)

Code:
"Java2D Disposer" daemon prio=10 tid=0x0301d470 nid=0xfe4 in Object.wait() [0x03a0f000..0x03a0fd6c]
        at java.lang.Object.wait(Native Method)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x107ae440> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at sun.java2d.Disposer.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

"com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2" daemon prio=5 tid=0x03061998 nid=0x3a0 in Object.wait(
) [0x036bf000..0x036bfd6c]
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
        - locked <0x1072f0b8> (a com.mchange.v2.async.ThreadPoolAsynchronousRunner)

"com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1" daemon prio=5 tid=0x03061030 nid=0xa54 in Object.wait(
) [0x0367f000..0x0367fd6c]
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
        - locked <0x1072f0b8> (a com.mchange.v2.async.ThreadPoolAsynchronousRunner)

"com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0" daemon prio=5 tid=0x03064a60 nid=0xbc0 in Object.wait(
) [0x0363f000..0x0363fd6c]
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
        - locked <0x1072f0b8> (a com.mchange.v2.async.ThreadPoolAsynchronousRunner)

"Thread-8" daemon prio=5 tid=0x030648f8 nid=0x568 in Object.wait() [0x035ff000..0x035ffd6c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1072f6f8> (a java.util.TaskQueue)
        at java.util.TimerThread.mainLoop(Unknown Source)
        - locked <0x1072f6f8> (a java.util.TaskQueue)
        at java.util.TimerThread.run(Unknown Source)

"com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2" daemon prio=5 tid=0x02f6c780 nid=0xf88 in Object.wait(
) [0x034bf000..0x034bfd6c]
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
        - locked <0x105bd398> (a com.mchange.v2.async.ThreadPoolAsynchronousRunner)

"com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1" daemon prio=5 tid=0x02f6f460 nid=0xbfc in Object.wait(
) [0x0347f000..0x0347fd6c]
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
        - locked <0x105bd398> (a com.mchange.v2.async.ThreadPoolAsynchronousRunner)

"com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0" daemon prio=5 tid=0x02f6f2f8 nid=0x128 in Object.wait(
) [0x0343f000..0x0343fd6c]
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
        - locked <0x105bd398> (a com.mchange.v2.async.ThreadPoolAsynchronousRunner)

"Thread-4" daemon prio=5 tid=0x02f59de0 nid=0x14c in Object.wait() [0x033ff000..0x033ffd6c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x105bd4d0> (a java.util.TaskQueue)
        at java.util.TimerThread.mainLoop(Unknown Source)
        - locked <0x105bd4d0> (a java.util.TaskQueue)
        at java.util.TimerThread.run(Unknown Source)

"DestroyJavaVM" prio=5 tid=0x00036330 nid=0x1d8 waiting on condition [0x00000000..0x0007fad8]

"pool-1-thread-4" prio=5 tid=0x02effd48 nid=0x980 in Object.wait() [0x033af000..0x033afd6c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1155)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:405)
        - locked <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:351)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:466)

        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:125)
        at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:360)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:122)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:125)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1309)
        at com.sec.eds.speed.server.util.CommonUtil.completeDataIdWork(CommonUtil.java:408)
        at com.sec.eds.speed.server.datamgr.CmdMsrTable.run(CmdMsrTable.java:429)
        at com.sec.eds.speed.server.datamgr.CmdData2.run(CmdData2.java:185)
        at edu.emory.mathcs.backport.java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.runAndReset(FutureTask.java:198)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Sch
eduledThreadPoolExecutor.java:102)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Sc
heduledThreadPoolExecutor.java:189)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledT
hreadPoolExecutor.java:213)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)

        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
        at java.lang.Thread.run(Unknown Source)

"pool-1-thread-3" prio=5 tid=0x02efe068 nid=0xe4c in Object.wait() [0x0336f000..0x0336fd6c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1155)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:405)
        - locked <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:351)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:466)

        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:125)
        at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:360)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:122)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:125)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1309)
        at com.sec.eds.speed.server.datamgr.CmdMsrTable.run(CmdMsrTable.java:95)
        at com.sec.eds.speed.server.datamgr.CmdData2.run(CmdData2.java:185)
        at edu.emory.mathcs.backport.java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.runAndReset(FutureTask.java:198)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Sch
eduledThreadPoolExecutor.java:102)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Sc
heduledThreadPoolExecutor.java:189)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledT
hreadPoolExecutor.java:213)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)

        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
        at java.lang.Thread.run(Unknown Source)

"pool-1-thread-2" prio=5 tid=0x02e10a10 nid=0xa8c in Object.wait() [0x0332f000..0x0332fd6c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1155)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:405)
        - locked <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:351)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:466)

        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:125)
        at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:360)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:122)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:125)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1309)
        at com.sec.eds.speed.server.util.CommonUtil.completeDataIdWork(CommonUtil.java:408)
        at com.sec.eds.speed.server.datamgr.CmdMsrTable.run(CmdMsrTable.java:429)
        at com.sec.eds.speed.server.datamgr.CmdData2.run(CmdData2.java:185)
        at edu.emory.mathcs.backport.java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.runAndReset(FutureTask.java:198)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Sch
eduledThreadPoolExecutor.java:102)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Sc
heduledThreadPoolExecutor.java:189)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledT
hreadPoolExecutor.java:213)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)

        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
        at java.lang.Thread.run(Unknown Source)

"pool-1-thread-1" prio=5 tid=0x00a42578 nid=0x964 in Object.wait() [0x032ef000..0x032efd6c]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1155)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:405)
        - locked <0x105c4a18> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:351)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:466)

        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:125)
        at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:360)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:122)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:125)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1309)
        at com.sec.eds.speed.server.datamgr.CmdMsrTable.run(CmdMsrTable.java:95)
        at com.sec.eds.speed.server.datamgr.CmdData2.run(CmdData2.java:185)
        at edu.emory.mathcs.backport.java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.runAndReset(FutureTask.java:198)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Sch
eduledThreadPoolExecutor.java:102)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Sc
heduledThreadPoolExecutor.java:189)
        at edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledT
hreadPoolExecutor.java:213)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)

        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
        at java.lang.Thread.run(Unknown Source)

"Signal Dispatcher" daemon prio=10 tid=0x00a37808 nid=0xb98 waiting on condition [0x00000000..0x00000000]

"Finalizer" daemon prio=9 tid=0x00a24038 nid=0x808 in Object.wait() [0x02baf000..0x02bafd6c]
        at java.lang.Object.wait(Native Method)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x10500b08> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x00a22ca8 nid=0xebc in Object.wait() [0x02b6f000..0x02b6fd6c]
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Unknown Source)
        at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
        - locked <0x10500b70> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=5 tid=0x0003f670 nid=0x4bc runnable

"VM Periodic Task Thread" prio=10 tid=0x00a28590 nid=0xa90 waiting on condition
"Suspend Checker Thread" prio=10 tid=0x00a25cd8 nid=0xe8c runnable


Top
 Profile  
 
 Post subject: c3p0
PostPosted: Wed Jan 03, 2007 4:03 am 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
Maybe is a problem with your c3p0 pool configuration.

You should configure it through hibernate properties

Here is an example from the reference documentation:

Code:
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 5:23 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I guess if you're using different threads, that you should use the sessionFactory.getCurrentSession() method, after configuring the current_session_context_class property to thread value.

See http://www.hibernate.org/hib_docs/v3/re ... properties

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 5:54 am 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
dominicus//

I already configured that file.

I think that is not concern with my problem.

Thank you for your advice^^.
==============================

batmat//

Hmm.. What you said is maybe one of things I must check.

I will try.. hope solve the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 10:49 am 
Newbie

Joined: Tue Apr 18, 2006 9:57 am
Posts: 18
I recommend to use the JNDI pool manager of tomcat, the c3p0 has to many problems with the memory and resources.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 8:23 pm 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
batmat//

I changed all of my java source files from openSession() to getCurrentSession().

But, problem occurred and logger said "already session closed!!..".

Problem happend between beginSession and tx.commit if there was call for common util class method using session.

It is natural because I use singleton pattern in my hibernateUtil concern to SessionFactory that you can see my first post top above from this thread.

So I try use only one session by getCurrentSession in concurrent env.

And I will change getCurrentSession method to openSession all of my java files.

And I will watch what happen..

anyway, your advice point me that I must check.

---------------------------------------------------------
mcorrea//

I will change c3p0 to JNDI pool manager of tomcat for a temporary.

I do hope solve my problem~ ^^;;


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 3:14 am 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
kyb -- this looks like pool exhaustion, like somewhere you are checking out Connections but not necessarily returning them. You can debug this by upgrading to c3p0-0.9.1-pre11 if you haven't already, and setting the following config parameters in a c3p0 properties file:

Code:
  c3p0.unreturnedConnectionTimeout=10
  c3p0.debugUnreturnedConnectionStackTraces=true


The first line tells c3p0 to automatically close Connections if your program fails to do so within 10 seconds of checkout. (You might try a different timeout, depends on what your app does.) The second line asks c3p0 to log stack traces of the Connection checkouts for which Connections eventually failed to be checked in. Pay careful attention to these stack traces: they indicate a codepath where Connections are used by the application but not closed 100% reliably.

Be sure you are using Java's reliable resource cleanup idiom to close Connections or Sessions to avoid Connection leaks in a long-running server process. That would be like this:

Code:
   Session mySession = null;
   try
   {
     mySession = ...; //however you initialize Sessions

     // do some hibernate work...
   }
   finally
   {
      try { if (mySession != null) mySession.close(); }
      catch(Exception e) { log("Exception on close", e); }
   }


Note that if you are working with more than one closable resource,
you must make a SEPARATE, BEST ATTEMPT to close each resource:

Code:
   
   Session mySession = null;
   InputStream is = null;
   try
   {
     mySession = ...; //however you initialize Sessions
     is = createControlFileInputStream();

     // read from the input stream
     // do some hibernate work, based on control file...
   }
   finally
   {
      try { if (is != null) is.close(); }
      catch(Exception e) { log("Exception on close", e); }

      try { if (mySession != null) mySession.close(); }
      catch(Exception e) { log("Exception on close", e); }
   }


Note that the closing of the two separate resources occurs in
distinct try/catch clocks (nested within the finally block). This is
important -- if you put them in a single try/catch (or don't nest
any try/catch blocks), a failure to close() the first resource leads
to a failure to close() the second.

By the way, none of this is c3p0-specific advice. It's widely
applicable good Java hygiene. Connection pool exhaustion is just one
of many ways a failure to close() resources property can manifest
itself.

Good luck!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 3:24 am 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
mcorrea -- you've complained a couple of times in a nonspecific way about c3p0's memory and resource usage. we corresponded once about a configuration issue, but you've never reported any memory or resource utilization issues. i'm sorry c3p0 didn't work for you, and certainly don't mind your using or recommending others' libraries, but it'd be nice to get better information about what you dislike, so that maybe i can fix it.

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 6:53 am 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
swaldman//

Thank you very much for your detailed describe and advice.

Yes! Your assumption is right.

My programs have bugs......use session but not close it.

I searched source files and found those mistakes.

After modified source files, now programs are running for 5-6 hours.

I will follow your advice..will upgrade c3p0 to pre11 and insert that config parameters in a c3p0 properties file.

Thank you so much^^.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 9:18 pm 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
kyb -- glad stuff seems to be working better. once you get all the cleanup carefully handled, you should be able to do without the extra config. setting a longish unreturnedConnectionTimeout does little harm, but debugUnreturnedConnectionStackTraces slows things down, so you should turn it off once you've resolved all the leaks. good luck!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.