From d742434b4e8038af371d922a2e5de6c54fca8a7f Mon Sep 17 00:00:00 2001 From: gojomo Date: Fri, 8 Jul 2011 21:59:05 +0000 Subject: [PATCH] [HER-1911] make writer-pool 'maxActive' setting adjustable mid-crawl * WriterPool make new LARGEST_MAX_ACTIVE (255) the capacity of the reuse-pool, so that the maxActive property may vary up to that and still work; also handle more gracefully the failure of trying to use a larger number than the capacity (writer gets closed early rather than left hanging open) --- .../main/java/org/archive/io/WriterPool.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/commons/src/main/java/org/archive/io/WriterPool.java b/commons/src/main/java/org/archive/io/WriterPool.java index 0c228a0d..7bf35cfa 100644 --- a/commons/src/main/java/org/archive/io/WriterPool.java +++ b/commons/src/main/java/org/archive/io/WriterPool.java @@ -44,17 +44,15 @@ public abstract class WriterPool { */ final protected AtomicInteger serialNo; - /** - * Don't enforce a maximum number of idle instances in pool. - * To do so means GenericObjectPool will close files prematurely. - */ - protected static final int NO_MAX_IDLE = -1; - /** * Default maximum active number of files in the pool. */ public static final int DEFAULT_MAX_ACTIVE = 1; + /** Assumed largest possible value of maxActive; pool will have this + * maximum capacity, so dynamic changes beyond this number won't work. */ + protected static final int LARGEST_MAX_ACTIVE = 255; + /** * Maximum time to wait on a free file before considering * making a new one (if not already at max) @@ -102,7 +100,7 @@ public abstract class WriterPool { this.settings = settings; this.maxActive = poolMaximumActive; this.maxWait = poolMaximumWait; - availableWriters = new ArrayBlockingQueue(maxActive, true); + availableWriters = new ArrayBlockingQueue(LARGEST_MAX_ACTIVE, true); this.serialNo = serial; } @@ -190,7 +188,10 @@ public abstract class WriterPool { } } } - availableWriters.offer(writer); + if(!availableWriters.offer(writer)) { + logger.log(Level.WARNING, "writer unreturnable to available pool; closing early"); + destroyWriter(writer); + } } /**