1 22 23 package org.jboss.aspects.asynchronous.concurrent; 24 25 import org.jboss.aspects.asynchronous.AsynchronousParameters; 26 import org.jboss.aspects.asynchronous.AsynchronousUserTask; 27 import org.jboss.aspects.asynchronous.ThreadManager; 28 import org.jboss.aspects.asynchronous.ThreadManagerRequest; 29 import org.jboss.aspects.asynchronous.common.ThreadManagerRequestImpl; 30 31 import java.util.ResourceBundle ; 32 33 37 38 public class ThreadManagerFactory 39 { 40 41 protected ThreadManager threadManager; 42 43 protected String DEFAULT_MIN_THREAD = "10"; 44 45 protected String DEFAULT_MAX_THREAD = "100"; 46 47 protected String DEFAULT_KEEP_ALIVE = "5000"; 48 49 protected String DEFAULT_IS_WAITING_WHEN_POOLSIZE_FULL = "FALSE"; 50 51 protected String DEFAULT_IS_POOLING = "TRUE"; 52 53 static protected String MIN_POOL_SIZE = "threadManager.minimumPoolsize"; 54 55 static protected String MAX_POOL_SIZE = "threadManager.maximumPoolsize"; 56 57 static protected String KEEP_ALIVE = "threadManager.keepAlive"; 58 59 static protected String IS_WAITING_WHEN_POOLSIZE_FULL = 60 61 "threadManager.isWaitingWhenPoolSize"; 62 63 static protected String IS_POOLING = 64 65 "threadManager.isPooling"; 66 67 static protected String PROPERTY_FILE = 68 69 "org.jboss.aspects.asynchronous.threadManager"; 70 71 protected static final ThreadManagerFactory threadManagerFactory = 72 73 new ThreadManagerFactory(); 74 75 static protected ResourceBundle rb; 76 77 static void initResourceBundle() 78 { 79 80 try 81 { 82 83 rb = ResourceBundle.getBundle(PROPERTY_FILE); 84 85 } 86 catch (Exception e) 87 { 88 89 91 } 92 93 } 94 95 private static String getString(String key, String defaultValue) 96 { 97 98 try 99 { 100 101 if (rb == null) 102 103 return defaultValue; 104 105 String value = rb.getString(key); 106 107 if (value == null) 108 109 return defaultValue; 110 111 else 112 113 return value; 114 115 } 116 catch (Exception e) 117 {} 118 119 return defaultValue; 120 121 } 122 123 protected ThreadManagerFactory() 124 { 125 126 initResourceBundle(); 127 128 threadManager = new ThreadManagerImpl(); 129 130 threadManager.setMinimumPoolSize(Integer.parseInt(getString(MIN_POOL_SIZE, DEFAULT_MIN_THREAD))); 131 132 threadManager.setMaximumPoolSize(Integer.parseInt(getString(MAX_POOL_SIZE, DEFAULT_MAX_THREAD))); 133 134 threadManager.setKeepAliveTime(Integer.parseInt(getString(KEEP_ALIVE, DEFAULT_KEEP_ALIVE))); 135 136 threadManager.setWaitWhenPoolSizeIsFull(Boolean 137 138 .valueOf(getString(IS_WAITING_WHEN_POOLSIZE_FULL, 139 140 DEFAULT_IS_WAITING_WHEN_POOLSIZE_FULL)) 141 142 .booleanValue()); 143 144 145 threadManager.setPooling(Boolean 146 147 .valueOf(getString(IS_POOLING, 148 149 DEFAULT_IS_POOLING)) 150 151 .booleanValue()); 152 153 } 154 155 static public ThreadManager getThreadManager() 156 { 157 158 return threadManagerFactory.threadManager; 159 160 } 161 162 static public ThreadManagerRequest createNewThreadManagerRequest(String id, 163 164 AsynchronousParameters inputParameters, 165 166 AsynchronousUserTask taskClassNameImpl, 167 168 long timeout) 169 { 170 171 return new ThreadManagerRequestImpl(id, 172 173 inputParameters, 174 175 taskClassNameImpl, 176 177 timeout); 178 179 } 180 181 } 182 | Popular Tags |