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:com.berwickheights.spring.svc.SendEmailSvcImpl.java

/**
 * Check that properties have been set correctly in bean definition
 *//*w  w  w.  ja  v a 2s .  c o m*/
public void afterPropertiesSet() throws Exception {
    Assert.notNull(emailSender, "emailSender must be set");
    Assert.notNull(from, "from must be set");
    Assert.isTrue(numWorkerThreads > 0, "numWorkerThreads must be greater than 0");

    // Set up thread pool to send email messages asynchronously
    threadPool = Executors.newFixedThreadPool(numWorkerThreads);
}

From source file:com.palantir.docker.compose.logging.FileLogCollector.java

@Override
public synchronized void startCollecting(DockerCompose dockerCompose) throws IOException, InterruptedException {
    if (executor != null) {
        throw new RuntimeException("Cannot start collecting the same logs twice");
    }/*from   ww  w. ja v  a2 s.c om*/
    List<ContainerName> containerNames = dockerCompose.ps();
    if (containerNames.size() == 0) {
        return;
    }
    executor = Executors.newFixedThreadPool(containerNames.size());
    containerNames.stream().map(ContainerName::semanticName)
            .forEachOrdered(container -> this.collectLogs(container, dockerCompose));
}

From source file:com.genentech.chemistry.openEye.apps.SDFMDLSSSMatcher.java

public SDFMDLSSSMatcher(String qFile, String outFile, boolean firstMatch, boolean printAll, int nCpu) {
    this.firstMatch = firstMatch;
    this.printAll = printAll;
    this.matcher = new MDLSSSMatcher(qFile);
    this.ofs = new oemolothread(outFile);
    this.nCpu = nCpu;

    this.executor = Executors.newFixedThreadPool(nCpu);
    this.completionService = new ExecutorCompletionService<Boolean>(executor);

    finder = new MDLSSSFind[nCpu];
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.data.KratuProcessor.java

public void processKratus(Long topAccountId, Date dateStart, Date dateEnd) throws InterruptedException {
    System.out.println("Processing Kratus for" + topAccountId);

    // We use a Latch so the main thread knows when all the worker threads are complete.
    final CountDownLatch latch = new CountDownLatch(1);
    Stopwatch stopwatch = Stopwatch.createStarted();

    RunnableKratu runnableKratu = createRunnableKratu(topAccountId, storageHelper, dateStart, dateEnd);

    ExecutorService executorService = Executors.newFixedThreadPool(1);
    runnableKratu.setLatch(latch);/*from www  .j a v  a 2 s .co m*/
    executorService.execute(runnableKratu);

    latch.await();
    stopwatch.stop();
}

From source file:koper.kafka.KafkaBatchSenderTest.java

/**
 * ?10??/*from   w  w  w . ja  v a  2s  .c  o m*/
 *   messageSender.send(topic2, msg) ???
 */
public void testInsertOrder() {

    int c = 100;
    int n = 10;
    for (int i = 0; i < c; i++) {

        ExecutorService executorService = Executors.newFixedThreadPool(16);

        int x = i;
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < n; j++) {
                    Order order = newOrder(x * 10 + j);
                    String newOrderId = orderMapper.insertOrder(order);
                    System.out.println("****** insert Order  " + newOrderId);
                }

            }
        });
    }
}

From source file:dk.dma.msiproxy.common.repo.ThumbnailService.java

@PostConstruct
private void init() {
    processPool = Executors.newFixedThreadPool(EXECUTOR_POOL_SIZE);

    // Enlist image types supported by vips (avoid gif)
    vipsFileTypes.add("image/bmp");
    vipsFileTypes.add("image/jpeg");
    vipsFileTypes.add("image/jpg");
    vipsFileTypes.add("image/tiff");
    vipsFileTypes.add("image/tif");
    vipsFileTypes.add("image/png");
}

From source file:com.netflix.conductor.core.execution.WorkflowSweeper.java

@Inject
public WorkflowSweeper(ExecutionDAO edao, MetadataDAO metadata, ObjectMapper om,
        WorkflowExecutor workflowProvider, Configuration config, QueueDAO queues) {
    this.om = om;
    this.ds = new DeciderService(metadata, edao, om);
    this.config = config;
    this.queues = queues;
    this.executorThreadPoolSize = config.getIntProperty("workflow.sweeper.thread.count", 5);
    this.es = Executors.newFixedThreadPool(executorThreadPoolSize);
    init(workflowProvider);/*from w w  w.  j  a v a  2 s.  co  m*/
    logger.info("Workflow Sweeper Initialized");
}

From source file:it.geosolutions.tools.io.CopyTreeTest.java

@Before
public void setUp() throws Exception {

    destMount = new File(TestData.file(this, "."), "test-data2");
    if (!destMount.exists()) {
        new File(destMount, "collector").mkdirs();
    }//from ww w  . j ava 2 s. c  om
    Assert.assertTrue(destMount.exists());

    testFile = TestData.file(this, "collector/569_PRO/RS1_geo8.xml");

    ex = Executors.newFixedThreadPool(2);

    if (ex == null || ex.isTerminated()) {
        throw new IllegalArgumentException(
                "Unable to run asynchronously using a terminated or null ThreadPoolExecutor");
    }

    cs = new ExecutorCompletionService<File>(ex);
}

From source file:com.dsclab.loader.app.Loader.java

public static void load(Configs prop)
        throws SQLException, ClassNotFoundException, InterruptedException, ExecutionException {
    int readThread = prop.getReadThread();
    int writeThread = prop.getWriteThread();
    ExecutorService readExecutor = Executors.newFixedThreadPool(readThread);
    ExecutorService writeExecutor = Executors.newFixedThreadPool(writeThread);
    LOG.info("Start load: writeThread:" + writeThread + ", readThread:" + readThread);
    BlockingQueue<List<String>> contentQueue = new LinkedBlockingQueue<>();

    int tableCount = tableTask.size();
    int sum = 0;//  w ww . j  av  a2  s  . c  o m
    for (int i = 0; i < tableCount; i++) {
        sum = sum + tableTask.get(i).getTaskSqlList().size();
    }
    for (int i = 0; i < sum; i++) {
        readExecutor.submit(new ProducerThread(prop.getInputURL(), contentQueue));
        writeExecutor.submit(new ConsumerThread(prop.getOutputURL(), contentQueue));
    }

    readExecutor.shutdown();
    readExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
    System.out.println("[CHIA7712] read threads end");
    writeExecutor.shutdown();
    writeExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
    System.out.println("[CHIA7712] write threads end");
}

From source file:com.digitalgeneralists.assurance.model.concurrency.AssuranceThreadPool.java

public void setNumberOfThreads(Integer numberOfThreads) {
    if ((numberOfThreads == null) || (numberOfThreads < 2)) {
        numberOfThreads = AssuranceThreadPool.DEFAULT_NUMBER_OF_THREADS;
    }/*  w w w  . ja  v a  2 s  .  c o  m*/
    this.threadPool = Executors.newFixedThreadPool(numberOfThreads);
}