Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1B5E3200BE8 for ; Fri, 23 Dec 2016 20:18:03 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 19E5B160B1F; Fri, 23 Dec 2016 19:18:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 40352160B0C for ; Fri, 23 Dec 2016 20:18:02 +0100 (CET) Received: (qmail 99691 invoked by uid 500); 23 Dec 2016 19:17:56 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 99673 invoked by uid 99); 23 Dec 2016 19:17:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2016 19:17:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 43EFD18128D for ; Fri, 23 Dec 2016 19:17:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.679 X-Spam-Level: X-Spam-Status: No, score=0.679 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Mr4i0ANZvyoR for ; Fri, 23 Dec 2016 19:17:54 +0000 (UTC) Received: from mail-pg0-f54.google.com (mail-pg0-f54.google.com [74.125.83.54]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id A6E6A5F1A0 for ; Fri, 23 Dec 2016 19:17:53 +0000 (UTC) Received: by mail-pg0-f54.google.com with SMTP id i5so46979911pgh.2 for ; Fri, 23 Dec 2016 11:17:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=FmafFz7b1y2+1OGvnHH1TXiJbQC+2Or/QAN/HQFp66M=; b=MNSe1eDMfY65JEDWcD9XeRiX2mDfrzo2dEr+p2WoX/mo27bR2ZuOlwxnlmklJWpbs+ JxRpYyYrmquL5Na+Fv5iPSbL/qU3AY6U6Aui1rbYbj+65CkCVHd4nXX/Bq4wb8tKnu0/ brLuezqlZ5YmhytA0yjL68njiT+snepTMm0Z1PSPZLwerJTx0spDqBBAm5uAFQc0f7Yk ngVBzvTax3bakFWz840eeIcLanBjMnoAZImzvfYNtJSQidgKGVRqpY4mlzoPfPs7YGyB ab1TKatMYUELy5JQP0B129c4sbtkVCBw1tuMpxc1Z92+rBIYQ4vGav+M4OTqPF2ujfrx pyRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=FmafFz7b1y2+1OGvnHH1TXiJbQC+2Or/QAN/HQFp66M=; b=pZJ6X9kD8me4emchvIZ5vwSYdJM/wR66AqBYKHKOarQHiKpNU5UJ4FPz5GYWokyXo+ sOzkSq2du4lmuouXqvOvbxM1Zns74GpKcu9vUxEbSA5vAnUtu1uJ/mmZYqOqemA/JYaK LEJNun6JFEPeN3uk8RXLe/zfzxK6IvYllewirkfNjfLt8/pne30CIta2U6qWThzwNqI1 nlzARBirQ2Wg+SemeLa5NeqjHrntm6gCjwZd2NpVu/By3VHC9NbqhT5YH/lKb/F8/G88 QEZKsykG9HzIr0KnG4gFjvaB8Furwn2o+whOcVM5pUK/c2Hl9CsarAJ4YBOfBrSl1EkY +5YA== X-Gm-Message-State: AIkVDXIyvnHeFMS+xF+mv1G9COoO7gbAivbEI+uGszyA6AkXp+94Tk2XImehQpyqsKoQ1A== X-Received: by 10.84.218.3 with SMTP id q3mr32030467pli.80.1482520662930; Fri, 23 Dec 2016 11:17:42 -0800 (PST) Received: from psteitz-mbp.local ([67.133.165.2]) by smtp.googlemail.com with ESMTPSA id p127sm62416938pfg.24.2016.12.23.11.17.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Dec 2016 11:17:42 -0800 (PST) Subject: Re: I need to close the connection, not return it back to the Connection Pool To: user@commons.apache.org References: <08110a1a-6319-58e0-81a0-7c95b8dd8935@k2data.com.cn> <88dfbe6a-bfb3-1471-1b38-88bab14f9fd6@gmail.com> <14f69d73-d4a4-6e3e-4c5e-203150d95066@k2data.com.cn> From: Phil Steitz Message-ID: <04ddd876-070f-87fb-eb8e-858d3b7ddaaf@gmail.com> Date: Fri, 23 Dec 2016 12:17:41 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <14f69d73-d4a4-6e3e-4c5e-203150d95066@k2data.com.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable archived-at: Fri, 23 Dec 2016 19:18:03 -0000 On 12/22/16 7:22 PM, =E7=8E=8B=E9=92=A6 wrote: > Hi Shawn & Phil: > > Thank you for your help. > > The scenario I faced is like this: > > In the usual work time, there will be plenty of connections to > the Impala Database. So I need a Connection Pool to manage them. > > When a query is executed for a long time and the client wants > to cancel it manually, closing the connection for this query > really is one solution (or maybe a poor solution.) OK, so the best solution would be to find a way to kill or set a timeout on the query, but I understand that may not be possible, so you want to be more brutal and kill the connection. The best here would be to upgrade to DBCP 2.2 and use the invalidate method that was added for this kind of use case. Upgrading to DBCP2/Pool2 has other benefits as well. =20 Phil > > And thank you for your help again. > > > Best Wishes > > Qin > > > > On 2016=E5=B9=B412=E6=9C=8823=E6=97=A5 04:47, Phil Steitz wrote: >> On 12/22/16 9:34 AM, Shawn Heisey wrote: >>> On 12/22/2016 4:49 AM, =E7=8E=8B=E9=92=A6 wrote: >>>> When I use DBCP-1.4 in my work, I need to close the >>>> connection >>>> which is generated by BasicDataSource. How can I do it? Close the >>>> connection, while not returning it back to the Connection Pool. >>> The PoolableConnection class (which I believe is the actual type of >>> object you will receive from the data source) has a >>> "reallyClose()" method. >>> >>> http://commons.apache.org/proper/commons-dbcp/api-1.4/org/apache/comm= ons/dbcp/PoolableConnection.html#reallyClose() >>> >>> >>> I'm no expert, but I think you might be able to cast the connection >>> received from BasicDataSource to the Poolable variety. >>> >>> If you intend to "reallyClose()" every connection (rather than >>> just some >>> of them), I do have to wonder why you're using DBCP at all.=20 >>> Obtaining >>> connections from JDBC directly and closing them normally would >>> accomplish the same thing without a code dependency and slightly >>> less >>> overhead. >> I agree with your statement about defeating the purpose of the pool >> if you do this every time. If done only when the client knows the >> connection is bad, the solution above will unfortunately leak pool >> capacity (reallyClose doesn't inform the pool that the checked out >> connection is never coming back). A sort of ugly workaround for >> that would be to enable abandoned connection cleanup, which would >> eventually clean these up. >> >> What you need to do to do this cleanly is to get the underlying >> GenericObjectPool to invalidate the PoolableConnection so its >> accounting is correctly updated. If you are willing to upgrade to >> DBCP 2, BasicDataSource now has an invalidateConnection method that >> handles this. If not, the only way to do this without leaking >> capacity is to do what the source for that method does, which >> requires that you get a reference to the underlying object pool. >> BasicDatasource does not expose that, so if you want to go this >> route, you need to manually create the GOP and use a >> PoolingDatasource. >> >> Phil >>> Thanks, >>> Shawn >>> >>> >>> ---------------------------------------------------------------------= >>> >>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>> For additional commands, e-mail: user-help@commons.apache.org >>> >>> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >> For additional commands, e-mail: user-help@commons.apache.org >> >> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org