If ocpl is a connection pool as the name suggests that it is then you
will not really create a new connection every time you call
ocpl.getConnection but instead you'll just get an initialized connection
that's not used.

Your second approach is not multithread safe.

d.

Vikramjit Singh wrote:
> Hi all,
>
> I have a doubt in which method is the proper way of getting connections. I
> am putting the connections in the server context, and getting  the
> connections from the context by
>
> ServletContext context = getServletContext();
> OracleConnectionPool ocpl =
> (OracleConnectionPool)context.getAttribute("CONNECTION_POOL");
> OracleConnection tmpDbCon = (OracleConnection)ocpl.getConnection();
>
> First Method:
> I usually get the connection by the above method by putting it in the doPost
> method of the servlet.
>
> like public void doPost(HttpServletRequest req, HttpServletResponse res){
>         ServletContext context = getServletContext();
>         OracleConnectionPool ocpl =
> (OracleConnectionPool)context.getAttribute("CONNECTION_POOL");
>         OracleConnection tmpDbCon = (OracleConnection)ocpl.getConnection();
> }
>
> My colleague says that this method has its overheads since each and
> everytime you fetch and release a connection. Which should be avoided.
>
> So she tried the second method
>
> Second Method:
>
> Instead of fetching the connection from doPost method, she put it in the
> init() method of the servlet like this
>
> public void init()
> {
>         ServletContext context = getServletContext();
>         OracleConnectionPool ocpl =
> (OracleConnectionPool)context.getAttribute("CONNECTION_POOL");
>         OracleConnection tmpDbCon = (OracleConnection)ocpl.getConnection();
>
> }
>
> Now the servlet will always have a connection. This connection shall be
> released only when the destroy() method of the servlet is called. She says
> this is better, since you dont everytime have to get and release the
> connection. You have assigned one connection to it. If many users access
> this servlet, then the service method shall handle it.
>
> Could some java gurus throw some light on this.
>
> Regards,
> Vikramjit Singh,
> Systems Engineer,
> GTL Ltd.
> Ph. 7612929-1031
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
>


--
David Mossakowski              [EMAIL PROTECTED]
Instinet Corporation                 212.310.7275



*******************************************************************************
<<Disclaimer>>

This message is intended only for the use of the Addressee and
may contain information that is PRIVILEGED and/or
CONFIDENTIAL or both.

This email is intended only for the personal and confidential use
of the recipient(s) named above.

If the reader of this email is not an intended recipient, you have
received this email in error and any review, dissemination,
distribution or copying is strictly prohibited.

If you have received this email in error, please notify the sender
immediately by return mail and permanently deleting the copy
you received.

Thank you.

*******************************************************************************

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to