java.util.concurrent.LinkedBlockingQueue.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中java.util.concurrent.LinkedBlockingQueue.<init>()方法的一些代码示例,展示了LinkedBlockingQueue.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedBlockingQueue.<init>()方法的具体详情如下:
包路径:java.util.concurrent.LinkedBlockingQueue
类名称:LinkedBlockingQueue
方法名:<init>

LinkedBlockingQueue.<init>介绍

[英]Creates a LinkedBlockingQueue with a capacity of Integer#MAX_VALUE.
[中]

代码示例

代码示例来源:origin: thinkaurelius/titan

private static ExecutorService getDefaultExecutor() {
    return new ThreadPoolExecutor(0, 1, KEEPALIVE_TIME, KEEPALIVE_UNIT, new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY);
  }
}

代码示例来源:origin: stackoverflow.com

class MyHouse {
  final BlockingQueue<Object> queue = new LinkedBlockingQueue<>();

  void eatFood() throws InterruptedException {
    // take next item from the queue (sleeps while waiting)
    Object food = queue.take();
    // and do something with it
    System.out.println("Eating: " + food);
  }

  void deliverPizza() throws InterruptedException {
    // in producer threads, we push items on to the queue.
    // if there is space in the queue we can return immediately;
    // the consumer thread(s) will get to it later
    queue.put("A delicious pizza");
  }
}

代码示例来源:origin: crossoverJie/JCSprout

BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
    .setNameFormat("consumer-%d")
    .setDaemon(true)
    .build();
ThreadPoolExecutor executor = new ThreadPoolExecutor(15, 15, 1, TimeUnit.MILLISECONDS, queue,namedThreadFactory);
    .setDaemon(true)
    .build();
ThreadPoolExecutor productExecutor = new ThreadPoolExecutor(2, 2, 1, TimeUnit.MILLISECONDS, queue,product);
  System.out.println("线程还在执行。。。");
System.out.println("main over");

代码示例来源:origin: oblac/jodd

public void start() {
  executorService = new ThreadPoolExecutor(
    corePoolSize,
    maximumPoolSize,
    keepAliveTimeMillis,
    TimeUnit.MILLISECONDS,
    new LinkedBlockingQueue<>(queueCapacity));
}

代码示例来源:origin: JanusGraph/janusgraph

private static ExecutorService getDefaultExecutor() {
    return new ThreadPoolExecutor(0, 1, KEEPALIVE_TIME, KEEPALIVE_UNIT,
        new LinkedBlockingQueue<>(), THREAD_FACTORY);
  }
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Creates a new channel. The channel should be registered after it's created.
 *
 * @param name the name of the channel.
 * @param channelHandler the handler for this channel.
 */
public Channel(String name, ChannelHandler<T> channelHandler) {
  this.name = name;
  this.channelHandler = channelHandler;
  executor = new ThreadPoolExecutor(1, 8, 15, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
}

代码示例来源:origin: stackoverflow.com

public static ExecutorService newFixedThreadPool(int nThreads) {
  return new ThreadPoolExecutor(nThreads, nThreads,
                 0L, TimeUnit.MILLISECONDS,
                 new LinkedBlockingQueue<Runnable>());
}

代码示例来源:origin: springside/springside4

public ThreadPoolExecutor build() {
    BlockingQueue<Runnable> queue = null;
    if (queueSize < 1) {
      queue = new LinkedBlockingQueue<Runnable>();
    } else {
      queue = new ArrayBlockingQueue<Runnable>(queueSize);
    }
    threadFactory = createThreadFactory(threadFactory, threadNamePrefix, daemon);
    if (rejectHandler == null) {
      rejectHandler = defaultRejectHandler;
    }
    return new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS, queue, threadFactory,
        rejectHandler);
  }
}

代码示例来源:origin: apache/activemq

private ThreadPoolExecutor createExecutor() {
    ThreadPoolExecutor exec = new ThreadPoolExecutor(0, 2, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), factory);
    exec.allowCoreThreadTimeOut(true);
    return exec;
  }
}

代码示例来源:origin: stackoverflow.com

tp = new ThreadPoolExecutor(5, 5, 60, TimeUnit.SECONDS,
          new LinkedBlockingQueue<Runnable>());
tp.allowCoreThreadTimeOut(true);

代码示例来源:origin: stackoverflow.com

int corePoolSize = 60;
int maximumPoolSize = 80;
int keepAliveTime = 10;

BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(maximumPoolSize);
Executor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue);

代码示例来源:origin: Graylog2/graylog2-server

private ExecutorService executorService(final MetricRegistry metricRegistry, final String nameFormat,
                    final int corePoolSize, final int maxPoolSize, final int keepAliveTime) {
  final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
  return new InstrumentedExecutorService(
      new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS,
          new LinkedBlockingQueue<Runnable>(), threadFactory),
      metricRegistry,
      name(this.getClass(), "executor-service"));
}

代码示例来源:origin: stackoverflow.com

public static ExecutorService newFixedThreadPool(int nThreads) {
  return new ThreadPoolExecutor(nThreads, nThreads,
                 0L, TimeUnit.MILLISECONDS,
                 new LinkedBlockingQueue<Runnable>());
}

代码示例来源:origin: thinkaurelius/titan

public WorkerPool(int numThreads) {
  processor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(128));
  processor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
}

代码示例来源:origin: square/okhttp

/**
 * Create a cache which will reside in {@code directory}. This cache is lazily initialized on
 * first access and will be created if it does not exist.
 *
 * @param directory a writable directory
 * @param valueCount the number of values per cache entry. Must be positive.
 * @param maxSize the maximum number of bytes this cache should use to store
 */
public static DiskLruCache create(FileSystem fileSystem, File directory, int appVersion,
  int valueCount, long maxSize) {
 if (maxSize <= 0) {
  throw new IllegalArgumentException("maxSize <= 0");
 }
 if (valueCount <= 0) {
  throw new IllegalArgumentException("valueCount <= 0");
 }
 // Use a single background thread to evict entries.
 Executor executor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS,
   new LinkedBlockingQueue<>(), Util.threadFactory("OkHttp DiskLruCache", true));
 return new DiskLruCache(fileSystem, directory, appVersion, valueCount, maxSize, executor);
}

代码示例来源:origin: stackoverflow.com

public static ExecutorService newFixedThreadPool(int nThreads) {
   return new ThreadPoolExecutor(nThreads, nThreads,
                  0L, TimeUnit.MILLISECONDS,
                  new LinkedBlockingQueue<Runnable>());
 }

public static ExecutorService newCachedThreadPool() {
  return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                 60L, TimeUnit.SECONDS,
                 new SynchronousQueue<Runnable>());
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Executor getExecutor(URL url) {
  String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
  int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
  int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
  return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,
      queues == 0 ? new SynchronousQueue<Runnable>() :
          (queues < 0 ? new LinkedBlockingQueue<Runnable>()
              : new LinkedBlockingQueue<Runnable>(queues)),
      new NamedInternalThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Executor getExecutor(URL url) {
  String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
  int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
  int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
  return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,
      queues == 0 ? new SynchronousQueue<Runnable>() :
          (queues < 0 ? new LinkedBlockingQueue<Runnable>()
              : new LinkedBlockingQueue<Runnable>(queues)),
      new NamedInternalThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}

代码示例来源:origin: qunarcorp/qmq

@Bean(name = "workerExecutor")
  public ThreadPoolExecutor workerExecutor(@Value("${executor.coreSize}") int core,
                       @Value("${executor.maxSize}") int max,
                       @Value("${executor.queueSize}") int queueSize) {
    return new ThreadPoolExecutor(core, max, 1,
        TimeUnit.MINUTES, new LinkedBlockingQueue<>(queueSize));
  }
}

代码示例来源:origin: immutables/immutables

private static ListeningExecutorService newExecutor() {
  return MoreExecutors.listeningDecorator(
    MoreExecutors.getExitingExecutorService(
      new ThreadPoolExecutor(
        DEFAULT_THREAD_POOL_CORE_SIZE,
        DEFAULT_THREAD_POOL_MAXIMUM_SIZE,
        DEFAULT_THREAD_POOL_KEEP_ALIVE_MILLIS,
        TimeUnit.MILLISECONDS,
        new LinkedBlockingQueue<Runnable>(),
        DEFAULT_THREAD_FACTORY)));
 }
}

相关文章

微信公众号

最新文章

更多