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.espertech.esperio.db.core.ExecutorServices.java

public ExecutorServices(EPServiceProviderSPI spi, Map<String, Executor> workQueue) {
    this.services = new HashMap<String, ExecutorService>();

    for (Map.Entry<String, Executor> entry : workQueue.entrySet()) {
        Executor queue = entry.getValue();

        if (queue.getNumThreads() <= 0) {
            continue;
        }//  ww w.  j  a v  a2s.  c  om

        LinkedBlockingQueue<Runnable> runnableQueue = new LinkedBlockingQueue<Runnable>();
        ExecutorService service = new ThreadPoolExecutor(queue.getNumThreads(), queue.getNumThreads(), 1000,
                TimeUnit.SECONDS, runnableQueue);
        services.put(entry.getKey(), service);
    }

    try {
        spi.getContext().bind("EsperIODBAdapter/ExecutorServices", this);
    } catch (NamingException e) {
        log.error("Error binding executor service: " + e.getMessage(), e);
    }
}

From source file:edu.iu.harp.schstatic.TaskMonitor.java

TaskMonitor(int taskID, T task, Submitter<I> submitter, int numTasks, Semaphore barrier1) {
    this.taskObject = task;
    this.taskObject.setTaskID(taskID);
    this.taskObject.setNumTasks(numTasks);
    this.taskObject.setSubmitter(submitter);
    this.inputQueue = new LinkedBlockingQueue<>();
    this.outputQueue = new LinkedBlockingQueue<>();
    this.inputCount = 0;
    this.outputCount = 0;
    this.errorCount = 0;
    this.barrier1 = barrier1;
    this.barrier2 = new Semaphore(0);
}

From source file:edu.iu.harp.schdynamic.DynamicScheduler.java

public DynamicScheduler(List<T> tasks) {
    inputQueue = new LinkedBlockingDeque<>();
    outputQueue = new LinkedBlockingQueue<>();
    threads = null;/*from w  ww  .  j a va  2  s.  com*/
    inputCount = 0;
    outputCount = 0;
    errorCount = 0;
    isRunning = false;
    isPausing = false;
    barrier1 = new Semaphore(0);
    numTaskMonitors = tasks.size();
    this.tasks = tasks;
    taskMonitors = new ArrayList<>();
    for (T task : tasks) {
        taskMonitors.add(new TaskMonitor<>(inputQueue, outputQueue, task, barrier1));
    }
}

From source file:org.apache.ambari.event.AsyncDispatcher.java

public AsyncDispatcher() {
    this(new HashMap<Class<? extends Enum>, EventHandler>(), new LinkedBlockingQueue<Event>());
}

From source file:ok.MyService2.java

@Override
protected Task<BlockingQueue> createTask() {
    final Task<BlockingQueue> task;
    task = new Task<BlockingQueue>() {

        @Override//from  ww w  .  j  ava2  s.  co  m
        protected BlockingQueue call() throws Exception {
            BlockingQueue result = new LinkedBlockingQueue<String>();

            PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
            cm.setMaxTotal(100);

            CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();
            try {
                ExecutorService executor = Executors.newFixedThreadPool(sites.size());
                List<Future<String>> results = new ArrayList<Future<String>>();
                for (int i = 0; i < sites.size(); i++) {
                    HttpGet httpget = new HttpGet(sites.get(i));
                    Callable worker = new MyCallable(httpclient, httpget);
                    Future<String> res = executor.submit(worker);
                    results.add(res);
                    // String url = hostList[i];
                    //   Runnable worker = new MyRunnable(url);
                    //   executor.execute(worker);
                    //   executor.submit(null);

                }
                executor.shutdown();
                // Wait until all threads are finish
                //                   while (!executor.isTerminated()) {
                //
                //                   }
                for (Future<String> element : results) {
                    result.add(element.get());
                }
                System.out.println("\nFinished all threads");

            } finally {
                httpclient.close();
            }
            return result;
        }

    };
    return task;
}

From source file:org.apache.axis2.transport.base.threads.NativeWorkerPool.java

public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, String threadGroupName,
        String threadGroupId) {/* w  ww. j  av  a2s.  c  o m*/

    if (log.isDebugEnabled()) {
        log.debug("Using native util.concurrent package..");
    }
    blockingQueue = (queueLength == -1 ? new LinkedBlockingQueue<Runnable>()
            : new LinkedBlockingQueue<Runnable>(queueLength));
    executor = new Axis2ThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, blockingQueue,
            new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId));
}

From source file:com.mnt.base.mail.AsyncMailHelper.java

private AsyncMailHelper() {
    mailQueue = new LinkedBlockingQueue<MailHolder>();
}

From source file:de.thischwa.pmcms.view.renderer.ExportThreadPoolController.java

ExportThreadPoolController(int threadMaxCountPerCore) {
    int threadPoolSize = 1;
    if (threadMaxCountPerCore != 0)
        threadPoolSize = threadMaxCountPerCore * Constants.CPU_COUNT;
    threadPool = new ThreadPool(threadPoolSize, threadPoolSize, 0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());

    logger.info("ExportThreadPoolController thread pool size initialized with: " + threadPoolSize);
}

From source file:com.tobrun.android.notify.lib.NotifyManager.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    // will not be called during a configuration change
    super.onCreate(savedInstanceState);
    setRetainInstance(true);/*from   w  w w  .  j  ava 2 s .  co m*/
    mQueue = new LinkedBlockingQueue<Notify>();
    mHandler = new Handler();
}

From source file:com.adobe.plugins.FastCanvas.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    Log.i("CANVAS", "FastCanvas initialize");
    super.initialize(cordova, webView);
    mMessageQueue = new LinkedBlockingQueue<FastCanvasMessage>();
    mActivity = cordova.getActivity();/*from   w ww  .j  ava  2  s . co m*/
    mCanvasView = new FastCanvasView(mActivity);
    theCanvas = this;
    mCordovaView = webView;
    initView();
}