You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mark Thomas (JIRA)" <ji...@apache.org> on 2016/03/15 21:28:33 UTC
[jira] [Resolved] (POOL-280) Code cleanups for
GenericObjectPool.borrowObject(...)
[ https://issues.apache.org/jira/browse/POOL-280?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mark Thomas resolved POOL-280.
------------------------------
Resolution: Fixed
Fix Version/s: (was: 2.5)
2.4.3
Thanks for the patch.
It has been applied along with a similar fix in GKOP.
> Code cleanups for GenericObjectPool.borrowObject(...)
> -----------------------------------------------------
>
> Key: POOL-280
> URL: https://issues.apache.org/jira/browse/POOL-280
> Project: Commons Pool
> Issue Type: Improvement
> Affects Versions: 2.2
> Reporter: Jacopo Cappellato
> Priority: Minor
> Fix For: 2.4.3
>
> Attachments: POOL-280.patch
>
>
> In the attached patch you will find 2 minor code cleanups (no functional changes) in order to slightly simplify the code:
> # removed an if block that was unnecessary from DefaultPooledObject.deallocate()
> # removed some duplicate code from the two blocks of an if-else statement in GenericObjectPool.borrowObject(...); the original code was:
> {code}
> while (p == null) {
> create = false;
> if (blockWhenExhausted) {
> p = idleObjects.pollFirst();
> if (p == null) {
> p = create();
> if (p != null) {
> create = true;
> }
> }
> if (p == null) {
> if (borrowMaxWaitMillis < 0) {
> p = idleObjects.takeFirst();
> } else {
> p = idleObjects.pollFirst(borrowMaxWaitMillis,
> TimeUnit.MILLISECONDS);
> }
> }
> if (p == null) {
> throw new NoSuchElementException(
> "Timeout waiting for idle object");
> }
> if (!p.allocate()) {
> p = null;
> }
> } else {
> p = idleObjects.pollFirst();
> if (p == null) {
> p = create();
> if (p != null) {
> create = true;
> }
> }
> if (p == null) {
> throw new NoSuchElementException("Pool exhausted");
> }
> if (!p.allocate()) {
> p = null;
> }
> }
> ...
> }
> {code}
> and the new code is:
> {code}
> while (p == null) {
> create = false;
> p = idleObjects.pollFirst();
> if (p == null) {
> p = create();
> if (p != null) {
> create = true;
> }
> }
> if (p == null) {
> if (blockWhenExhausted) {
> if (borrowMaxWaitMillis < 0) {
> p = idleObjects.takeFirst();
> } else {
> p = idleObjects.pollFirst(borrowMaxWaitMillis,
> TimeUnit.MILLISECONDS);
> }
> if (p == null) {
> throw new NoSuchElementException(
> "Timeout waiting for idle object");
> }
> } else {
> throw new NoSuchElementException("Pool exhausted");
> }
> }
> if (!p.allocate()) {
> p = null;
> }
> ...
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)