List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
From source file:httpscheduler.GenericRequestListenerThread.java
public GenericRequestListenerThread(final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(1000); //System.out.println("Request Listener Thread created"); }
From source file:com.bt.aloha.batchtest.WeekendBatchTest.java
protected static void configure(BatchTest batchTest) throws Exception { Properties properties = new Properties(); InputStream is = new FileInputStream(CONFIG_FILE); properties.load(is);// w w w .ja v a2 s . c om is.close(); sleepTime = Integer.parseInt(properties.getProperty("sleepTime", Integer.toString(defaultSleepTime))); batchTest.setAudioFileUri(properties.getProperty("audioFileUri", "/provisioned/behave.wav")); stop = Boolean.parseBoolean(properties.getProperty("stop", "false")); batchTest.setNumberOfRuns(Integer.parseInt(properties.getProperty("numberOfRuns", "1000"))); int concurrentStarts = Integer.parseInt(properties.getProperty("numberOfConcurrentStarts", "4")); batchTest.setNumberOfConcurrentStarts(concurrentStarts); if (executorService == null) executorService = Executors.newFixedThreadPool(concurrentStarts); batchTest.setExecutorService(executorService); batchTest.setMaximumScenarioCompletionWaitTimeSeconds( Integer.parseInt(properties.getProperty("maximumScenarioCompletionWaitTimeSeconds", "60"))); addBatchScenarios(batchTest); }
From source file:httpscheduler.LateBindingRequestListenerThread.java
public LateBindingRequestListenerThread(final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(22); System.out.println("Request Listener Thread created"); }
From source file:com.totalchange.bunman.cddb.impl.CddbQuerierImpl.java
public CddbQuerierImpl(String hostname, int port, int maxConnections, long idleTimeout) { GenericObjectPool<CDDB> pool = new GenericObjectPool<CDDB>(new CddbPoolableObjectFactory(hostname, port)); pool.setMaxActive(maxConnections);/* w w w .j a va 2s. co m*/ pool.setMinEvictableIdleTimeMillis(idleTimeout); pool.setTimeBetweenEvictionRunsMillis(TIME_BETWEEN_EVICTION_RUNS); this.cddbPool = pool; this.executor = Executors.newFixedThreadPool(maxConnections); }
From source file:gobblin.configuration.StateTest.java
/** * This test checks that state object is thread safe. We run 2 threads, one of them continuously adds and removes key/values * to the state and other thread calls getProperties. *///from www . ja v a 2 s . c o m @Test public void testGetPropertiesThreadSafety() { try { final State state = new State(); for (int i = 0; i < 1000; i++) { state.setProp(Integer.toString(i), Integer.toString(i)); } ExecutorService executorService = Executors.newFixedThreadPool(2); executorService.submit(new Runnable() { @Override public void run() { for (int j = 0; j < 1000; j++) { for (int i = 0; i < 1000; i++) { try { state.removeProp(Integer.toString(i)); state.setProp(Integer.toString(i), Integer.toString(i)); } catch (Throwable t) { exceptions.add(t); } } } } }); executorService.submit(new Runnable() { @Override public void run() { for (int i = 0; i < 1000; i++) { try { state.getProperties().get(Integer.toString(i)); } catch (Throwable t) { exceptions.add(t); } } } }); executorService.shutdown(); if (!executorService.awaitTermination(100, TimeUnit.SECONDS)) { throw new RuntimeException("Executor service still running"); } } catch (Throwable t) { Assert.fail("Concurrency test failed", t); } if (!this.exceptions.isEmpty()) { Assert.fail("Concurrency test failed with first exception: " + ExceptionUtils.getFullStackTrace(this.exceptions.poll())); } }
From source file:com.googlecode.jcimd.TcpNetConnectionFactory.java
public TcpNetConnectionFactory(String host, int port, String username, String password, int timeout) { super();//from w ww.j a va 2 s . co m this.host = host; this.port = port; this.username = username; this.password = password; this.timeout = timeout; this.executor = Executors.newFixedThreadPool(5); }
From source file:edu.stolaf.cs.wmrserver.TestJobEngine.java
TestJobEngine(Configuration conf) { _conf = conf;// w w w . ja va 2 s.c o m _allowTestJobs = _conf.getBoolean("wmr.tests.allow", false); _jobQueue = Executors.newFixedThreadPool(POOL_SIZE); _jobs = new HashMap<Long, Future<TestJobResult>>(); }
From source file:ws.salient.aws.SessionsIT.java
@Before public void before() { accountId = "test"; sessionId = UUID.randomUUID().toString(); System.setProperty("kie.maven.settings.custom", "src/test/resources/settings.xml"); Application.unpackRepository("/maven.zip"); executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1); json = new ObjectMapper().findAndRegisterModules().registerModules(new AmazonModule()); provider = new AmazonClientProvider(); store = new DynamoDBStore(provider.getDynamoDB(), provider.getAWSKMS(), json, executor); sessions = new Sessions(new AmazonS3Repository(provider.getAmazonS3()), new DynamoDBProfiles(provider.getDynamoDB(), provider.getAWSKMS(), json), store, Guice.createInjector(provider), executor, executor); }
From source file:com.wso2telco.dep.mediator.util.MessagePersistor.java
private MessagePersistor() { FileReader fileReader = new FileReader(); String file = CarbonUtils.getCarbonConfigDirPath() + File.separator + FileNames.MEDIATOR_CONF_FILE.getFileName(); Map<String, String> mediatorConfMap = fileReader.readPropertyFile(file); String noOfThreads = mediatorConfMap.get("numberOfThreads"); executorService = Executors.newFixedThreadPool(Integer.parseInt(noOfThreads)); dbservice = new RequestDAO(); }
From source file:com.wenyu.clustertools.Flush.java
@Override public void execute() { ExecutorService executor = Executors.newFixedThreadPool(parallel); Map<ClusterToolCmd.Node, Future<Void>> futures = new HashMap<>(); for (ClusterToolCmd.Node node : nodes) { futures.put(node, executor.submit(new Executor(node))); }// w w w. j ava 2 s . c o m for (Map.Entry<ClusterToolCmd.Node, Future<Void>> future : futures.entrySet()) { try { future.getValue().get(Constants.MAX_PARALLEL_WAIT_IN_SEC, TimeUnit.SECONDS); } catch (Exception ex) { System.out .println(String.format("%s failed with error: %s", future.getKey().server, ex.toString())); ex.printStackTrace(); } } }