Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 85559 invoked from network); 9 Oct 2003 13:33:41 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 9 Oct 2003 13:33:41 -0000 Received: (qmail 7660 invoked by uid 500); 9 Oct 2003 13:33:24 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 7640 invoked by uid 500); 9 Oct 2003 13:33:24 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 7606 invoked from network); 9 Oct 2003 13:33:23 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by daedalus.apache.org with SMTP; 9 Oct 2003 13:33:23 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A7auy-00085q-00 for ; Thu, 09 Oct 2003 15:33:24 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: dev@cocoon.apache.org Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A7aux-00085i-00 for ; Thu, 09 Oct 2003 15:33:23 +0200 Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A7aux-0001im-00 for ; Thu, 09 Oct 2003 15:33:23 +0200 From: Olivier Billard Subject: Re: Use of a connection in an avalon component Date: Thu, 09 Oct 2003 15:33:21 +0200 Lines: 38 Message-ID: References: <3F855E35.9090001@anyware-tech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20030916 X-Accept-Language: fr, fr-fr, en, en-us In-Reply-To: <3F855E35.9090001@anyware-tech.com> Sender: news X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N On 09/10/2003 15:10, Sylvain Wallez wrote: > Olivier Billard wrote: > >> Hi all ! >> >> I wonder how to use a DataSourceComponent and its connection in a >> custom cocoon avalon component, that is ThreadSafe, to use all >> performance and connection pool used in Cocoon. >> >> Should I : >> - get a connection via datasource.getConnection() and close() it for >> each public method call, >> - get a connection in the initialize() method from the interface >> Initializable, close() it on the dispose() method from Disposable >> interface, and only create a Statement for each public method call ? >> - implement another avalon interface, like Runnable, to get/relase >> the Connection ? >> >> I looked for exemples in the databases block, but the helpers are not >> Components. > > > > If your component is ThreadSafe, a single instance of it will exist in > the whole system. JDBC connections being non thread safe, you *must* get > and close them at each call. Don't be afraid to call close(): the > connection you get is a wrapper managed by the DataSourceComponent which > puts back the real request in the pool for later reuse when close() is > called on the wrapper. by later reuse, do you mean datasource.getConnection() ? -- Olivier