Example usage for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue

List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue

Introduction

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

Prototype

public LinkedBlockingQueue() 

Source Link

Document

Creates a LinkedBlockingQueue with a capacity of Integer#MAX_VALUE .

Usage

From source file:com.mirth.connect.server.controllers.DonkeyEngineController.java

private List<ChannelFuture> submitHaltTasks(Set<String> channelIds, ChannelTaskHandler handler) {
    List<ChannelFuture> futures = new ArrayList<ChannelFuture>();

    /*/*from  w w w  . j ava  2 s.c o  m*/
     * If no handler is given then use the default handler to that at least errors will be
     * logged out.
     */
    if (handler == null) {
        handler = new LoggingTaskHandler();
    }

    for (String channelId : channelIds) {
        /*
         * Shutdown the executor to prevent any new tasks from being submitted. This needs to be
         * called once outside of the synchronized block in order to halt certain actions such
         * as restoring server configuration.
         */
        shutdownExecutor(channelId);

        synchronized (this) {
            /*
             * Shutdown the executor to prevent any new tasks from being submitted. This needs
             * to be called once inside the synchronized block in case multiple halts were
             * performed.
             */
            shutdownExecutor(channelId);

            /*
             * Create a new executor to submit the halt task to. Since all the submit methods
             * are synchronized, it is not possible for any other tasks for this channel to
             * occur before the halt task.
             */
            ExecutorService engineExecutor = new ThreadPoolExecutor(0, 1, 10L, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<Runnable>());
            engineExecutors.put(channelId, engineExecutor);

            ChannelTask haltTask = new HaltTask(channelId);
            haltTask.setHandler(handler);
            futures.add(haltTask.submitTo(engineExecutor));
        }

    }
    return futures;
}

From source file:com.emc.esu.test.EsuApiTest.java

@Test
public void testIssue9() throws Exception {
    int threadCount = 10;

    final int objectSize = 10 * 1000 * 1000; // size is not a power of 2.
    final MetadataList list = new MetadataList();
    list.addMetadata(new Metadata("test-data", null, true));
    final EsuApi api = esu;
    final List<Identifier> cleanupList = cleanup;
    ThreadPoolExecutor executor = new ThreadPoolExecutor(threadCount, threadCount, 0, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
    try {/* w w  w. j a  v a 2  s . com*/
        for (int i = 0; i < threadCount; i++) {
            executor.execute(new Thread() {
                public void run() {
                    ObjectId oid = api.createObjectFromStream(null, list, new RandomInputStream(objectSize),
                            objectSize, null);
                    cleanupList.add(oid);
                }
            });
        }
        while (true) {
            Thread.sleep(1000);
            if (executor.getActiveCount() < 1)
                break;
        }
    } finally {
        executor.shutdown();
    }
}

From source file:com.emc.atmos.api.test.AtmosApiClientTest.java

@Test
public void testIssue9() throws Exception {
    int threadCount = 10;

    final int objectSize = 10 * 1000 * 1000; // not a power of 2
    final AtmosApi atmosApi = api;
    final List<ObjectIdentifier> cleanupList = new ArrayList<ObjectIdentifier>();
    ThreadPoolExecutor executor = new ThreadPoolExecutor(threadCount, threadCount, 0, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
    try {/* w w w .j a v a2  s .  com*/
        for (int i = 0; i < threadCount; i++) {
            executor.execute(new Thread() {
                public void run() {
                    CreateObjectRequest request = new CreateObjectRequest();
                    request.content(new RandomInputStream(objectSize)).contentLength(objectSize)
                            .userMetadata(new Metadata("test-data", null, true));
                    ObjectId oid = atmosApi.createObject(request).getObjectId();
                    cleanupList.add(oid);
                }
            });
        }
        while (true) {
            Thread.sleep(1000);
            if (executor.getActiveCount() < 1)
                break;
        }
    } finally {
        executor.shutdown();
        cleanup.addAll(cleanupList);
        if (cleanupList.size() < threadCount)
            Assert.fail("At least one thread failed");
    }
}

From source file:com.emc.atmos.api.test.AtmosApiClientTest.java

@Test
public void testMultiThreadedBufferedWriter() throws Exception {
    int threadCount = 20;
    ThreadPoolExecutor executor = new ThreadPoolExecutor(threadCount, threadCount, 5000, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());

    // test with String
    List<Throwable> errorList = Collections.synchronizedList(new ArrayList<Throwable>());
    for (int i = 0; i < threadCount; i++) {
        executor.execute(/*  w  ww  .jav  a  2s  .  c  o m*/
                new ObjectTestThread<String>("Test thread " + i, "text/plain", String.class, errorList));
    }
    do {
        Thread.sleep(500);
    } while (executor.getActiveCount() > 0);
    if (!errorList.isEmpty()) {
        for (Throwable t : errorList)
            t.printStackTrace();
        Assert.fail("At least one thread failed");
    }

    // test with JAXB bean
    try {
        for (int i = 0; i < threadCount; i++) {
            executor.execute(new ObjectTestThread<AccessTokenPolicy>(
                    createTestTokenPolicy("Test thread " + i, "x.x.x." + i), "text/xml",
                    AccessTokenPolicy.class, errorList));
        }
        do {
            Thread.sleep(500);
        } while (executor.getActiveCount() > 0);
    } finally {
        executor.shutdown();
    }
    if (!errorList.isEmpty()) {
        for (Throwable t : errorList)
            t.printStackTrace();
        Assert.fail("At least one thread failed");
    }
}