Example usage for java.util.concurrent Executors newFixedThreadPool

List of usage examples for java.util.concurrent Executors newFixedThreadPool

Introduction

In this page you can find the example usage for java.util.concurrent Executors newFixedThreadPool.

Prototype

public static ExecutorService newFixedThreadPool(int nThreads) 

Source Link

Document

Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue.

Usage

From source file:io.pcp.parfait.benchmark.StandardMetricThroughPutBenchmark.java

public StandardMetricThroughPutBenchmark(int numThreads, int numCounters, int iterations, boolean startPcp,
        boolean usePerMetricLock) {
    this.numThreads = numThreads;
    this.numCounters = numCounters;
    this.iterations = iterations;
    this.startPcp = startPcp;
    this.usePerMetricLock = usePerMetricLock;
    this.executorService = Executors.newFixedThreadPool(this.numThreads);
}

From source file:com.emc.storageos.systemservices.impl.resource.CallHomeServiceImpl.java

private synchronized static ExecutorService getExecutorServiceInstance() {
    if (executorService == null) {
        executorService = Executors.newFixedThreadPool(FIXED_THREAD_POOL_SIZE);
    }/*  www  . j  ava2 s . co m*/
    return executorService;
}

From source file:com.ironiacorp.http.impl.httpclient3.HttpJobRunnerHttpClient3.java

public void run() {
    ExecutorService executor = Executors.newFixedThreadPool(maxThreadsCount);
    ExecutorCompletionService<HttpJob> queue = new ExecutorCompletionService<HttpJob>(executor);
    List<Future<?>> workers = new ArrayList<Future<?>>();

    for (HttpJob job : jobs) {
        if (HttpMethod.GET == job.getMethod()) {
            GetRequest request = new GetRequest(httpClient, job);
            Future<HttpJob> jobStatus = queue.submit(request);
            workers.add(jobStatus);/*www.  j  a v  a 2s . co m*/
            continue;
        }
        if (HttpMethod.POST == job.getMethod()) {
            PostRequest request = new PostRequest(httpClient, job);
            Future<HttpJob> jobStatus = queue.submit(request);
            workers.add(jobStatus);
            continue;
        }
        // TODO: job cannot be handled, what to do?
    }

    while (!workers.isEmpty()) {
        Iterator<Future<?>> i = workers.iterator();
        while (i.hasNext()) {
            try {
                Future<?> future = i.next();
                // future.get(timeout, TimeUnit.MILLISECONDS);
                future.get();
                i.remove();
                // } catch (TimeoutException e) {
            } catch (InterruptedException ie) {
                System.out.println(ie.getMessage());
            } catch (ExecutionException ee) {
                System.out.println(ee.getMessage());
                i.remove();
            }
        }
    }

    executor.shutdown();
}

From source file:cn.wanghaomiao.seimi.core.SeimiContext.java

public SeimiContext() {
    register(ScanConfig.class);
    init();/*from w  w w . j a va  2 s  .  c o  m*/
    if (!CollectionUtils.isEmpty(crawlers)) {
        prepareCrawlerModels();
        workersPool = Executors.newFixedThreadPool(
                BASE_THREAD_NUM * Runtime.getRuntime().availableProcessors() * crawlers.size());
        prepareWorkerThread();
    } else {
        logger.error("can not find any crawlers,please check!");
    }
}

From source file:com.replaymod.replaystudio.launcher.DaemonLauncher.java

public void launch(CommandLine cmd) throws Exception {
    int threads = Integer.parseInt(cmd.getOptionValue('d', "" + Runtime.getRuntime().availableProcessors()));
    worker = Executors.newFixedThreadPool(threads);

    System.setOut(new PrintStream(systemOut = new ThreadLocalOutputStream(System.out)));
    ServerSocket serverSocket = new ServerSocket(PORT);
    System.out.println("Daemon started on port " + PORT + " with " + threads + " worker threads.");
    while (!Thread.interrupted()) {
        Socket socket = serverSocket.accept();
        try {/*from   w  ww .j  av  a  2s .  c  o m*/
            Client client = new Client(socket);
            new Thread(client).start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.kordamp.javatrove.example06.AppModule.java

protected void bindExecutorService() {
    bind(ExecutorService.class)
            .toInstance(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
}

From source file:com.google.wireless.speed.speedometer.AccountSelector.java

public AccountSelector(Context context, Checkin checkin) {
    this.context = context;
    this.checkin = checkin;
    this.checkinExecutor = Executors.newFixedThreadPool(1);
}

From source file:io.pcp.parfait.benchmark.CPUThreadTest.java

private void runBenchmark(boolean cpuTracingEnabled, CPUThreadTestRunner.CpuLookupMethod cpuLookupMethod) {
    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    List<CPUThreadTestRunner> executions = newArrayList();

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    threadBean.setThreadCpuTimeEnabled(cpuTracingEnabled);

    threadBean.setThreadContentionMonitoringEnabled(true);

    long begin = currentTimeMillis();

    for (int i = 0; i < numThreads; i++) {
        CPUThreadTestRunner cpuThreadTestRunner = new CPUThreadTestRunner(iterations, cpuLookupMethod);
        executorService.execute(cpuThreadTestRunner);
        executions.add(cpuThreadTestRunner);
    }/*w w  w .ja  v a  2 s.co  m*/

    awaitExecutionCompletion(executorService);

    long end = currentTimeMillis();
    long timeTakenms = end - begin;

    report(executions, timeTakenms, iterations, cpuTracingEnabled, cpuLookupMethod);
}

From source file:com.suneee.core.realize.ImStarter.java

public static void start() {
    if (imConnectionMap.size() > 0) {
        return;/* ww w  .  j  a  va  2 s  .  c  o m*/
    }
    List<Account> lsac = getiAccountService().getAllAccount(new AccountExample());
    List<Map<String, String>> imAccount = new ArrayList<Map<String, String>>();
    Map<String, String> romap = null;
    String oldJid = "";
    for (int i = 0; i < lsac.size(); i++) {
        Account acc = lsac.get(i);
        oldJid = acc.getUsername() + ImStarter.serviceName;
        if (imConnectionMap.containsKey(oldJid)) {
            continue;
        }
        ;

        romap = new HashMap<String, String>();
        romap.put(ImConstants.JID, oldJid);
        romap.put(ImConstants.USER_PASSWORD, acc.getPlainPassword());
        romap.put(ImConstants.SERVER_NAME, ImGlobals.getXMLProperty(ImConstants.SERVER_NAME));
        romap.put(ImConstants.SERVER_PORT, ImGlobals.getXMLProperty(ImConstants.SERVER_PORT));
        romap.put(ImConstants.VCODE, acc.getvCode());
        imAccount.add(romap);
    }
    //List<Map<String, String>>  ImAccount2 =   ImGlobals.getImXMLProperties("ImAccount");
    int ImStartCount = imAccount.size();
    if (ImStartCount > 0) {
        ExecutorService executor = Executors.newFixedThreadPool(ImStartCount);
        for (int i = 0; i < ImStartCount; i++) {
            executor.execute(new ImStarter((Map<String, String>) imAccount.get(i)));
        }
    }
}

From source file:com.hortonworks.streamline.streams.notification.service.NotificationQueueHandler.java

public NotificationQueueHandler(int nThreads) {
    // TODO: evaluate ThreadPoolExecutor with bounded queue size
    executorService = Executors.newFixedThreadPool(nThreads);
    taskMap = new ConcurrentHashMap<>();
}