1 17 18 package org.apache.geronimo.connector.work.pool; 19 20 import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor; 21 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; 22 import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 34 public class WorkExecutorPoolImpl implements WorkExecutorPool { 35 36 39 private ThreadPoolExecutor pooledExecutor; 40 private static Log log = LogFactory.getLog(WorkExecutorPoolImpl.class); 41 42 49 public WorkExecutorPoolImpl(int maxSize) { 50 pooledExecutor = new ThreadPoolExecutor(1, maxSize, 1, TimeUnit.MINUTES, new LinkedBlockingQueue()); 51 56 } 57 58 63 public void execute(Runnable work) { 64 if(pooledExecutor.getPoolSize() == pooledExecutor.getMaximumPoolSize()) { 65 log.warn("Maximum Pool size has been exceeded. Current Pool Size = "+pooledExecutor.getMaximumPoolSize()); 66 } 67 68 pooledExecutor.execute(work); 69 } 70 71 74 public int getPoolSize() { 75 return pooledExecutor.getPoolSize(); 76 } 77 78 81 public int getMaximumPoolSize() { 82 return pooledExecutor.getMaximumPoolSize(); 83 } 84 85 89 public void setMaximumPoolSize(int maxSize) { 90 pooledExecutor.setMaximumPoolSize(maxSize); 91 } 92 93 public WorkExecutorPool start() { 94 throw new IllegalStateException ("This pooled executor is already started"); 95 } 96 97 101 public WorkExecutorPool stop() { 102 int maxSize = getMaximumPoolSize(); 103 pooledExecutor.shutdown(); 104 return new NullWorkExecutorPool(maxSize); 105 } 106 107 } 108 | Popular Tags |