Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion MySQL connection pooling with C3P0
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ross A. Baker  
View profile  
 More options Apr 27 2011, 10:46 am
From: "Ross A. Baker" <ba...@alumni.indiana.edu>
Date: Wed, 27 Apr 2011 10:46:30 -0400
Local: Wed, Apr 27 2011 10:46 am
Subject: Re: [scalatra-user] Re: MySQL connection pooling with C3P0
withValue one sets the value for the life of the block you pass it, so
dlSession would be null again after the before filter.  I think you
want:

    before {
       dlSession.value = SessionFactory.newSession
       dlSession.value.bindToCurrentThread
    }

    after {
      dlSession.value.unbindFromCurrentThread
      dlSession.value.close
      dlSession.value = null
    }

Alternatively you could implement Handler:

   trait DlSessionSupport extends Handler {
     val dlSession = new DynamicVariable[Session](null)

     abstract override def handle(req: HttpServletRequest, resp:
HttpServletResponse) {
       dlSession.withValue(SessionFactory.newSession) {
         dlSession.value.bindToCurrentThread
         try {
           super.handle(request, response)
         } finally {
           dlSession.value.close
           dlSession.value.unbindFromCurrentThread
         }
       }
     }
   }

   class DailyLifFilter extends ScalatraFilter with ScalateSupport
with DlSessionSupport

On Wed, Apr 27, 2011 at 10:36 AM, Dustin Withers <fadedd...@gmail.com> wrote:
> Where should I bind that variable? In a companion object to the
> Filter? Or should I still do it in my Filters class? Like:
> class DailyLifFilter extends ScalatraFilter with ScalateSupport with
> DatabaseInit {
>  val dlSession = new DynamicVariable[Session](null)

>  before {
>    dlSession.withValue(SessionFactory.newSession) {
>      dlSession.value.bindToCurrentThread
>    }
>  }

>  after {
>    dlSession.value.close
>    dlSession.value.unbindFromCurrentThread
>  }
> }

> On Apr 27, 9:12 am, Wille Faler <wille.fa...@gmail.com> wrote:
>> Hmm, making it an instance variable of your filter is not thread-safe, so
>> you should probably bind your session to a DynamicVariable/ThreadLocal
>> (DynamicVariable is Scala's equivalent of ThreadLocal)..

>> On 27 April 2011 15:10, Dustin Withers <fadedd...@gmail.com> wrote:

>> > Should something like the following work?

>> > class DailyLifFilter extends ScalatraFilter with ScalateSupport {
>> >  var dlSession:Session = null

>> >  before {
>> >    dlSession = SessionFactory.newSession
>> >    dlSession.bindToCurrentThread
>> >  }

>> >  after {
>> >    dlSession.close
>> >    dlSession.unbindFromCurrentThread
>> >  }
>> > ....

>> > Thanks,
>> > -dustin

>> > On Apr 27, 9:01 am, Wille Faler <wille.fa...@gmail.com> wrote:
>> > > You're probably leaking sessions and connections, as you are not closing
>> > > them or unbinding the session after a request:

>> > > session.close
>> > > session.unbindFromCurrentThread

>> > > On 27 April 2011 14:37, Dustin Withers <fadedd...@gmail.com> wrote:

>> > > > Hello all,

>> > > > I'm new to Scala and new to Scalatra, heck I'm kinda new to Java web
>> > > > development other than a bunch of Oracle work in another life. Anyhow,
>> > > > I'm having some trouble with MySQL and C3P0 connection pooling . The
>> > > > code can be seen here:
>> > > >https://gist.github.com/944244

>> > > > Originally I wasn't using any kind of connection pooling and I
>> > > > eventually exhausted my connections. Now instead of exhausting
>> > > > connections the app seems to run out of C3P0 connections and then
>> > > > locks up with no logging in the console and no CPU usage but the
>> > > > thread count goes up each time I request a page.

>> > > > I've played with all of C3P0's settings and I can stave off the
>> > > > failure by increasing MaxPoolSize but eventually after a enough page
>> > > > requests the app hangs.

>> > > > Any thoughts? Should I bother the people on the Squeryl mailing list?

>> > > > Thanks much for your time,
>> > > > -dustin

--
Ross A. Baker
ba...@alumni.indiana.edu
Indianapolis, IN, USA

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.