|
Jetty example source code file (ThreadPoolTest.java)
The Jetty ThreadPoolTest.java source codepackage org.mortbay.thread; import junit.framework.TestCase; public class ThreadPoolTest extends TestCase { int _jobs; long _result; Runnable _job = new Runnable() { public void run() { long t = System.currentTimeMillis()%1000; long r=t; for (int i=0;i<t;i++) r+=i; synchronized(ThreadPoolTest.class) { _jobs++; _result+=r; } } }; public void testQueuedThreadPool() throws Exception { QueuedThreadPool tp= new QueuedThreadPool(); tp.setMinThreads(5); tp.setMaxThreads(10); tp.setMaxIdleTimeMs(1000); tp.setSpawnOrShrinkAt(2); tp.setThreadsPriority(Thread.NORM_PRIORITY-1); tp.start(); assertEquals(5,tp.getThreads()); Thread.sleep(200); assertEquals(5,tp.getIdleThreads()); tp.dispatch(_job); Thread.sleep(200); tp.dispatch(_job); Thread.sleep(200); assertEquals(5,tp.getThreads()); assertEquals(5,tp.getIdleThreads()); for (int i=0;i<1000;i++) tp.dispatch(_job); Thread.sleep(200); assertEquals(0,tp.getQueueSize()); assertTrue(tp.getIdleThreads()>5); int threads=tp.getThreads(); assertTrue(threads>5); Thread.sleep(1100); assertTrue(tp.getThreads()<threads); assertTrue(tp.getThreads()>5); } } Other Jetty examples (source code examples)Here is a short list of links related to this Jetty ThreadPoolTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.