diff --git a/VERSION.txt b/VERSION.txt index 0676e4d5f35..26e56ce98f3 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -29,6 +29,7 @@ jetty-7.0.2-SNAPSHOT + JETTY-1157 Don't hold array passed in write(byte[]) + JETTY-1177 Allow error handler to set cacheControl + JETTY-1179 Persistant session tables created on MySQL use wrong datatype + + JETTY-1184 shrink thread pool even with frequent small jobs + COMETD-46 reset ContentExchange response content on resend jetty-7.0.1.v20091125 25 November 2009 diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index cd0d40f5e26..a5433631305 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -449,25 +449,21 @@ public class QueuedThreadPool extends AbstractLifeCycle implements ThreadPool, E job=_jobs.take(); else { - job=_jobs.poll(_maxIdleTimeMs,TimeUnit.MILLISECONDS); - - if (job==null) + // maybe we should shrink? + final int size=_threadsStarted.get(); + if (size>_minThreads) { - // maybe we should shrink? - final int size=_threadsStarted.get(); - if (size>_minThreads) + long last=_lastShrink.get(); + long now=System.currentTimeMillis(); + if (last==0 || (now-last)>_maxIdleTimeMs) { - long last=_lastShrink.get(); - long now=System.currentTimeMillis(); - if (last==0 || (now-last)>_maxIdleTimeMs) - { - shrink=_lastShrink.compareAndSet(last,now) && - _threadsStarted.compareAndSet(size,size-1); - if (shrink) - return; - } + shrink=_lastShrink.compareAndSet(last,now) && + _threadsStarted.compareAndSet(size,size-1); + if (shrink) + return; } } + job=_jobs.poll(_maxIdleTimeMs,TimeUnit.MILLISECONDS); } } } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index 7a8ef797c69..0e7b2dc0a88 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -21,8 +21,9 @@ import junit.framework.TestCase; public class QueuedThreadPoolTest extends TestCase { final AtomicInteger _jobs=new AtomicInteger(); + volatile long _sleep=100; - class Job implements Runnable + class RunningJob implements Runnable { public volatile boolean _running=true; public void run() @@ -30,7 +31,7 @@ public class QueuedThreadPoolTest extends TestCase try { while(_running) - Thread.sleep(100); + Thread.sleep(_sleep); } catch(Exception e) { @@ -39,10 +40,13 @@ public class QueuedThreadPoolTest extends TestCase _jobs.incrementAndGet(); } - }; + }; + + public void testThreadPool() throws Exception { + _sleep=100; QueuedThreadPool tp= new QueuedThreadPool(); tp.setMinThreads(5); tp.setMaxThreads(10); @@ -57,7 +61,7 @@ public class QueuedThreadPoolTest extends TestCase assertEquals(5,tp.getThreads()); assertEquals(5,tp.getIdleThreads()); - Job job=new Job(); + RunningJob job=new RunningJob(); tp.dispatch(job); Thread.sleep(200); assertEquals(5,tp.getThreads()); @@ -67,10 +71,10 @@ public class QueuedThreadPoolTest extends TestCase assertEquals(5,tp.getThreads()); assertEquals(5,tp.getIdleThreads()); - Job[] jobs = new Job[5]; + RunningJob[] jobs = new RunningJob[5]; for (int i=0;i