當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadFactoryBuilder.setNameFormat方法代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.ThreadFactoryBuilder.setNameFormat方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadFactoryBuilder.setNameFormat方法的具體用法?Java ThreadFactoryBuilder.setNameFormat怎麽用?Java ThreadFactoryBuilder.setNameFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.util.concurrent.ThreadFactoryBuilder的用法示例。


在下文中一共展示了ThreadFactoryBuilder.setNameFormat方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bulkAssign

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
/**
 * Run the bulk assign.
 * 
 * @param sync
 *          Whether to assign synchronously.
 * @throws InterruptedException
 * @return True if done.
 * @throws IOException
 */
public boolean bulkAssign(boolean sync) throws InterruptedException,
    IOException {
  boolean result = false;
  ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
  builder.setDaemon(true);
  builder.setNameFormat(getThreadNamePrefix() + "-%1$d");
  builder.setUncaughtExceptionHandler(getUncaughtExceptionHandler());
  int threadCount = getThreadCount();
  java.util.concurrent.ExecutorService pool =
    Executors.newFixedThreadPool(threadCount, builder.build());
  try {
    populatePool(pool);
    // How long to wait on empty regions-in-transition.  If we timeout, the
    // RIT monitor should do fixup.
    if (sync) result = waitUntilDone(getTimeoutOnRIT());
  } finally {
    // We're done with the pool.  It'll exit when its done all in queue.
    pool.shutdown();
  }
  return result;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:31,代碼來源:BulkAssigner.java

示例2: TBoundedThreadPoolServer

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
public TBoundedThreadPoolServer(Args options, ThriftMetrics metrics) {
  super(options);

  if (options.maxQueuedRequests > 0) {
    this.callQueue = new CallQueue(
        new LinkedBlockingQueue<Call>(options.maxQueuedRequests), metrics);
  } else {
    this.callQueue = new CallQueue(new SynchronousQueue<Call>(), metrics);
  }

  ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
  tfb.setDaemon(true);
  tfb.setNameFormat("thrift-worker-%d");
  executorService =
      new ThreadPoolExecutor(options.minWorkerThreads,
          options.maxWorkerThreads, options.threadKeepAliveTimeSec,
          TimeUnit.SECONDS, this.callQueue, tfb.build());
  serverOptions = options;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:TBoundedThreadPoolServer.java

示例3: createExecutor

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
private static ExecutorService createExecutor(
    int workerThreads, ThriftMetrics metrics) {
  CallQueue callQueue = new CallQueue(
      new LinkedBlockingQueue<Call>(), metrics);
  ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
  tfb.setDaemon(true);
  tfb.setNameFormat("thrift2-worker-%d");
  ThreadPoolExecutor pool = new ThreadPoolExecutor(workerThreads, workerThreads,
          Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());
  pool.prestartAllCoreThreads();
  return pool;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:13,代碼來源:ThriftServer.java

示例4: createExecutor

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
ExecutorService createExecutor(BlockingQueue<Runnable> callQueue,
                               int minWorkers, int maxWorkers) {
  ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
  tfb.setDaemon(true);
  tfb.setNameFormat("thrift-worker-%d");
  return new ThreadPoolExecutor(minWorkers, maxWorkers,
          Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:9,代碼來源:ThriftServerRunner.java

示例5: ReplicationSourceManager

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
/**
 * Creates a replication manager and sets the watch on all the other registered region servers
 * @param replicationQueues the interface for manipulating replication queues
 * @param replicationPeers
 * @param replicationTracker
 * @param conf the configuration to use
 * @param server the server for this region server
 * @param fs the file system to use
 * @param logDir the directory that contains all wal directories of live RSs
 * @param oldLogDir the directory where old logs are archived
 * @param clusterId
 */
public ReplicationSourceManager(final ReplicationQueues replicationQueues,
    final ReplicationPeers replicationPeers, final ReplicationTracker replicationTracker,
    final Configuration conf, final Server server, final FileSystem fs, final Path logDir,
    final Path oldLogDir, final UUID clusterId) {
  //CopyOnWriteArrayList is thread-safe.
  //Generally, reading is more than modifying.
  this.sources = new CopyOnWriteArrayList<ReplicationSourceInterface>();
  this.replicationQueues = replicationQueues;
  this.replicationPeers = replicationPeers;
  this.replicationTracker = replicationTracker;
  this.server = server;
  this.walsById = new HashMap<String, Map<String, SortedSet<String>>>();
  this.walsByIdRecoveredQueues = new ConcurrentHashMap<String, Map<String, SortedSet<String>>>();
  this.oldsources = new CopyOnWriteArrayList<ReplicationSourceInterface>();
  this.conf = conf;
  this.fs = fs;
  this.logDir = logDir;
  this.oldLogDir = oldLogDir;
  this.sleepBeforeFailover =
      conf.getLong("replication.sleep.before.failover", 30000); // 30 seconds
  this.clusterId = clusterId;
  this.replicationTracker.registerListener(this);
  this.replicationPeers.getAllPeerIds();
  // It's preferable to failover 1 RS at a time, but with good zk servers
  // more could be processed at the same time.
  int nbWorkers = conf.getInt("replication.executor.workers", 1);
  // use a short 100ms sleep since this could be done inline with a RS startup
  // even if we fail, other region servers can take care of it
  this.executor = new ThreadPoolExecutor(nbWorkers, nbWorkers,
      100, TimeUnit.MILLISECONDS,
      new LinkedBlockingQueue<Runnable>());
  ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
  tfb.setNameFormat("ReplicationExecutor-%d");
  tfb.setDaemon(true);
  this.executor.setThreadFactory(tfb.build());
  this.rand = new Random();
  this.latestPaths = Collections.synchronizedSet(new HashSet<Path>());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:51,代碼來源:ReplicationSourceManager.java

示例6: Executor

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
protected Executor(String name, int maxThreads,
    final Map<EventType, EventHandlerListener> eventHandlerListeners) {
  this.id = seqids.incrementAndGet();
  this.name = name;
  this.eventHandlerListeners = eventHandlerListeners;
  // create the thread pool executor
  this.threadPoolExecutor = new TrackingThreadPoolExecutor(
      maxThreads, maxThreads,
      keepAliveTimeInMillis, TimeUnit.MILLISECONDS, q);
  // name the threads for this threadpool
  ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
  tfb.setNameFormat(this.name + "-%d");
  this.threadPoolExecutor.setThreadFactory(tfb.build());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:ExecutorService.java

示例7: initScheduler

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
private static ScheduledExecutorService initScheduler(final String nameFormat) {
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    builder.setDaemon(true);
    builder.setNameFormat(nameFormat);
    return Executors.newScheduledThreadPool(1, builder.build());
}
 
開發者ID:florentw,項目名稱:bench,代碼行數:7,代碼來源:WatcherScheduler.java

示例8: main

import com.google.common.util.concurrent.ThreadFactoryBuilder; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    // must do this first for logback
    InternalLoggerFactory.setDefaultFactory( new Slf4JLoggerFactory( ));

    // args[0] should be the path of the transficc.props properties file
    String propsFilePath = args[0];
    Properties props = new Properties( );

    // load up the props for socket and DB config
    File pfile = new File( propsFilePath);
    logger.info( "Loading config from: " + propsFilePath);
    InputStream istrm = new FileInputStream( propsFilePath);
    props.load( istrm);
    String sport = props.getProperty( "SocketServerPort", "8080");
    logger.info( "Binding to port: " + sport);
    int port = Integer.parseInt( sport);

    // Create the transficc client, and the Q it uses to send events including
    // market data back to the thread that pushes updates on the web sockets.
    // Also an executor to provide a thread to run the TFClient. We keep a ref
    // to the transficc service so we can pass it to the web socket handler.
    LinkedBlockingQueue<JSON.Message> outQ = new LinkedBlockingQueue<JSON.Message>( );
    TFClient tfc = new TFClient( props, outQ);
    TransficcService tfs = tfc.GetService( );
    // need an executor for the thread that will intermittently send data to the client
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder( );
    builder.setDaemon( true);
    builder.setNameFormat( "transficc-%d");
    ExecutorService transficcExecutor = Executors.newSingleThreadExecutor( builder.build( ));
    FutureTask<String> transficcTask = new FutureTask<String>( tfc);
    transficcExecutor.execute( transficcTask);

    // Now we can create the pusher object and thread, which consumes the event
    // on the outQ. Those events originate with TFClient callbacks from transficc,
    // and also incoming websock events like subscription requests.
    WebSockPusher pusher = new WebSockPusher( props, outQ, tfs);
    ExecutorService pusherExecutor = Executors.newSingleThreadExecutor( builder.build( ));
    FutureTask<String> pusherTask = new FutureTask<String>( pusher);
    pusherExecutor.execute( pusherTask);

    // Compose the server components...
    EventLoopGroup bossGroup = new NioEventLoopGroup( 1);
    EventLoopGroup workerGroup = new NioEventLoopGroup( );
    try {
        ServerBootstrap b = new ServerBootstrap( );
        LoggingHandler lh = new LoggingHandler(LogLevel.INFO);
        ChannelInitializer ci = new ChannelInitializer<SocketChannel>( ) {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                p.addLast("encoder", new HttpResponseEncoder());
                p.addLast("decoder", new HttpRequestDecoder());
                p.addLast("aggregator", new HttpObjectAggregator(65536));
                p.addLast("handler", new WebSocketHandler( props, outQ));
            }
        };
        b.group( bossGroup, workerGroup).channel( NioServerSocketChannel.class).handler( lh).childHandler( ci);
        // Fire up the server...
        ChannelFuture f = b.bind( port).sync( );
        logger.info( "Server started");
        // Wait until the server socket is closed.
        f.channel( ).closeFuture( ).sync( );
    }
    finally {
        logger.info( "Server shutdown started");
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully( );
        workerGroup.shutdownGracefully();
        logger.info( "Server shutdown completed");
    }
}
 
開發者ID:SpreadServe,項目名稱:TFWebSock,代碼行數:72,代碼來源:ServerMain.java


注:本文中的com.google.common.util.concurrent.ThreadFactoryBuilder.setNameFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。