Hi really thanx for responses. Yes it is possible for this service, that
more users can connect this service at the same time, although there should
not be so big traffic. I must think about it yet how should I implement it.
 
    Thank s and regards Vladi

  _____  

From: Rajith Attapattu [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 10, 2007 1:26 AM
To: [email protected]
Subject: Re: Database connection


Since only one instance of the Service is used to serve all requests, your
code needs to be able to handle concurrency.
As anthony mentioned you may need to either use a connection pool or
synchronize access to the getConnection method. 
Apart from the connection method, if there is any shared state that is
modified as part of a request you may need to ensure it is done a in thread
safe way.

I would say that it depends on how frequently your service is accessed. 
If it's accessed once in a while then a synchronized getConnection method
might be cheaper than a thread pool.
Downfall is that concurrent requests are handled serially as they will block
on getConnection.

If it's accessed more often then offloading the burden of maintaining
connections to a connection pool might be a good idea.

Regards,

Rajith Attapattu
Red Hat.


On 10/9/07, Anthony Bull <[EMAIL PROTECTED]> wrote: 

If this is a service that more than one user can access I'd recommend
you use commons connection pooling to handle your connections.  That way
you just ask for a connection when you need one, and the commons library 
handles the creation.  Its not going to work very well if multiple
requests are being serviced using a single JDBC connection - and I'm not
even sure if it is threadsafe to do so.

Rajith Attapattu wrote: 
> If you deploy this service in Application Scope, then there will be
> one and only one instance of this service throught out the life time
> of the application.
> This way you only create your database connection once. 
>
> >Is it enough to create this service with application scope?
> So the answer is yes.
>
> Rajith Attapattu
> Red Hat.
>
> On 10/9/07, *VF* < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:
>
>     Hi all,
>     I would like to ask u, how can i utilize database connection in my
>     web
>     service. I have one web service with more methods in it. Id like 
>     to create
>     database connection just once and not with each call (each
>     operation works
>     with the same database connection) Is it enough to create this
>     service with 
>     application scope?
>
>     It looks like this:
>
>     Available services
>     stkdds
>
>     Service Description : stkdds
>     Service Status : Active
>     Available Operations 
>
>         * getFinishedOrderBin
>         * getOrderInfo
>         * updateOrder
>         * getUserInfo
>         * cancelOrder
>         * updateUser
>         * testOperation 
>         * getOrdersOverview
>         * getAllAccountsInfo
>         * getFinishedOrder
>         * getAccountInfo
>         * newOrder
>
>
>     And my code for database connection smth like this: 
>
>     public Connection setConnection() throws Exception {
>
>             if(conn != null){
>                     return conn;
>             }
>
>                  Class.forName ("org.firebirdsql.jdbc.FBDriver");
>                     conn = DriverManager.getConnection (p_connect_string,
>     sqlProps);
>                 return conn;
>
>
>
>
>     Thanks Vladi
>
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 
>     <mailto:[EMAIL PROTECTED]>
>     For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 
>     <mailto:[EMAIL PROTECTED]>
>
>


--

Anthony
-------------------------------------
Anthony Bull
Senior Developer 
Black Coffee Software Ltd
PO Box 10-192 The Terrace
Wellington, New Zealand

[EMAIL PROTECTED]
Ph  +64 4 472 8818
Fax +64 4 472 8811
------------------------------------- 
www.bcsoft.co.nz
---------------------------------------------------------------
This email may contain confidential or privileged information,
and is intended for use only by the addressee, or addressees. 
If you are not the intended recipient please advise the sender
immediately and do not copy, use or disclose the contents to
any other person or organisation.
Black Coffee Software Ltd accepts no responsibility for viruses 
received with this email, or to any changes made to the original
content. Any views or opinions expressed in this email may be
personal to the sender and are not necessarily those of Black
Coffee Software Ltd. 
---------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reply via email to