users@jersey.java.net

Re: Restful web service threading question

From: KSChan <mr.kschan_at_gmail.com>
Date: Tue, 22 Jan 2008 18:03:36 +0800

Marc,

I have solved the problem by using synchronization as normal threading
model.

In my case, I have concurrent AJAX calls to the web service in which the web
service obtains a JDBC connection from the glassfish connection pool. I
don't know whether the connection obtained is the same among the threads but
I got error when the DB operation is carried out sometimes.

My solution is like this ..

class Draft {
    String mutex = "";
    public Response webServiceOperation( ... ) {
        synchronized ( mutex ) {
            // obtain JDBC connection here
        }
        // carry DB operation here
    }
}

ks.

On Jan 21, 2008 4:57 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> CC'ing as ks is not a member of the users list.
>
> Paul.
>
> Marc Hadley wrote:
> > On Jan 19, 2008, at 1:31 AM, KSChan wrote:
> >>
> >> I am facing a problem that more than one concurrent web service
> >> threads are accessing the same resource and making something wrong ...
> >>
> >> How can I deal with this?
> >>
> > The default is that Jersey will create a new resource class instance for
> > each request (thread) so unless you have some static fields that aren't
> > protected by a mutex then you should be OK. Can you describe in a little
> > more detail what your resource class looks like and what problem you are
> > seeing ?
> >
> > Thanks,
> > Marc.
> >
> > ---
> > Marc Hadley <marc.hadley at sun.com>
> > CTO Office, Sun Microsystems.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >
>
> --
> | ? + ? = To question
> ----------------\
> Paul Sandoz
> x38109
> +33-4-76188109
>



-- 
I, have a dream. I want to make my dream come true.
http://mr.kschan.googlepages.com