Example usage for com.google.common.util.concurrent ThreadFactoryBuilder setNameFormat

List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder setNameFormat

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ThreadFactoryBuilder setNameFormat.

Prototype

public ThreadFactoryBuilder setNameFormat(String nameFormat) 

Source Link

Document

Sets the naming format to use when naming threads ( Thread#setName ) which are created with this ThreadFactory.

Usage

From source file:talkeeg.common.core.DataService.java

@Inject
DataService(IpcService ipc, ClientsAddressesService clientsAddresses) {
    this.ipc = ipc;
    this.clientsAddresses = clientsAddresses;
    IpcEntryHandler handler = new IpcEntryHandler() {
        @Override/*from   w w w  .j a va 2  s . c o  m*/
        public void handle(IpcEntryHandlerContext context, IpcEntry entry) {
            if (!(entry instanceof Command)) {
                throw new RuntimeException("Unsupported IpcEntry type: " + entry);
            }
            processCommand(context, (Command) entry);
        }
    };
    this.ipc.addIpcHandler(ACTION_DATA, handler);
    this.ipc.addIpcHandler(ACTION_DATA_RESPONSE, handler);
    final ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    builder.setDaemon(true);
    builder.setNameFormat(getClass().getSimpleName() + "-pool-%d");
    this.scheduledExecutorService = new ScheduledThreadPoolExecutor(1, builder.build());
}

From source file:org.jdag.master.MasterExecutor.java

/**
 * CTOR/*  www . j av a  2 s.  c o m*/
 */
@Inject
public MasterExecutor(WorkerSchedulingPolicy schedulingPolicy, Communicator communicator,
        ExecutionRegistry registry) {
    myWorkerSchedulingPolicy = schedulingPolicy;
    myStateRegistry = registry;
    myCommunicator = communicator;
    ThreadFactoryBuilder tfBuilder = new ThreadFactoryBuilder();
    ThreadFactory namedFactory = tfBuilder.setNameFormat(NodeExecutor.class.getSimpleName()).build();
    myScheduler = Executors.newScheduledThreadPool(1, namedFactory);
}

From source file:net.myrrix.common.parallel.Paralleler.java

/**
 * Run {@link Processor}, in as many threads as available cores, on values.
 * /*w  w  w.ja v a2s. c  om*/
 * @throws ExecutionException if any execution fails
 */
public void runInParallel() throws InterruptedException, ExecutionException {
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    if (name != null) {
        builder.setNameFormat(name + "-%s");
    }
    int numCores = Runtime.getRuntime().availableProcessors();
    ExecutorService executor = Executors.newFixedThreadPool(numCores, builder.build());
    try {
        runInParallel(executor, numCores);
    } finally {
        executor.shutdownNow();
    }
}

From source file:com.baidu.cc.ConfigChangedListener.java

/**
 * start listener thread/*from  w w  w. j a  v  a  2s  .  com*/
 */
public synchronized void start() {
    if (es == null) {
        ThreadFactoryBuilder tfbuilder = new ThreadFactoryBuilder();
        tfbuilder.setNameFormat("ConfigChangedListener-Thread");
        es = Executors.newSingleThreadExecutor(tfbuilder.build());
    }
    stop = false;
    es.execute(this);
}

From source file:talkeeg.common.core.PublicIpService.java

PublicIpService(Config config) {
    final String servicesString = config.getRoot().<String>getNode("net").getValue("publicIpServices", null);
    if (servicesString == null) {
        throw new NullPointerException(
                " 'net.publicIpServices' is null, but we need space delimited list of urls");
    }/*  ww w  . j a va2s .c om*/
    this.knowedServices = Collections
            .unmodifiableList(StringUtils.splitTo(new ArrayList<String>(), servicesString, ' '));
    final ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    builder.setDaemon(true);
    builder.setNameFormat(getClass().getSimpleName() + "-pool-%d");
    this.executor = Executors.newCachedThreadPool(builder.build());

    reload();
}

From source file:org.opendaylight.netvirt.vpnmanager.ArpScheduler.java

private ThreadFactory getThreadFactory(String threadNameFormat) {
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    builder.setNameFormat(threadNameFormat);
    builder.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override//from  w ww.j  a  v a2s.c  o  m
        public void uncaughtException(Thread t, Throwable e) {
            LOG.error("Received Uncaught Exception event in Thread: {}", t.getName(), e);
        }
    });
    return builder.build();
}

From source file:org.apache.bookkeeper.proto.NioServerSocketChannelManager.java

@Override
public Channel start(ServerConfiguration conf, ChannelPipelineFactory bookiePipelineFactory)
        throws IOException {
    BookieSocketAddress bookieAddress = Bookie.getBookieAddress(conf);
    ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
    String base = "bookie-" + conf.getBookiePort() + "-netty";
    this.channelFactory = new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(tfb.setNameFormat(base + "-boss-%d").build()),
            Executors.newCachedThreadPool(tfb.setNameFormat(base + "-worker-%d").build()));

    ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
    bootstrap.setPipelineFactory(bookiePipelineFactory);
    bootstrap.setOption("child.tcpNoDelay", conf.getServerTcpNoDelay());
    bootstrap.setOption("child.soLinger", 2);

    InetSocketAddress bindAddress;
    if (conf.getListeningInterface() == null) {
        // listen on all interfaces
        bindAddress = new InetSocketAddress(conf.getBookiePort());
    } else {//from w w  w .  j a  v  a  2s.  c o  m
        bindAddress = bookieAddress.getSocketAddress();
    }

    Channel listen = bootstrap.bind(bindAddress);
    return listen;
}

From source file:org.apache.hedwig.server.proxy.HedwigProxy.java

public void start() throws InterruptedException {
    final LinkedBlockingQueue<Boolean> queue = new LinkedBlockingQueue<Boolean>();

    new Thread(tg, new Runnable() {
        @Override/* w  w w .  j  a v a  2  s . co  m*/
        public void run() {
            client = new HedwigClient(cfg);
            ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
            serverSocketChannelFactory = new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(tfb.setNameFormat("HedwigProxy-NIOBoss-%d").build()),
                    Executors.newCachedThreadPool(tfb.setNameFormat("HedwigProxy-NIOWorker-%d").build()));
            initializeHandlers();
            initializeNetty();

            queue.offer(true);
        }
    }).start();

    queue.take();
}

From source file:com.proofpoint.event.collector.MainModule.java

@Provides
@Singleton/* w  w  w  . j a  va  2 s . c om*/
@Named("ScheduledCombinerLowPriorityExecutor")
private ScheduledExecutorService createScheduledCombinerLowPriorityExecutor(ServerConfig config) {
    ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder().setDaemon(true);
    if (config.getCombinerLowPriorityEventTypes().size() <= 0) {
        threadFactoryBuilder.setNameFormat("StoredObjectCombiner-Low-Disabled-Should-Not-Be-Used");
    } else {
        threadFactoryBuilder.setNameFormat("StoredObjectCombiner-Low-%s");
    }

    return newSingleThreadScheduledExecutor(threadFactoryBuilder.build());
}

From source file:com.proofpoint.event.collector.MainModule.java

@Provides
@Singleton/*from w w w  .ja v  a2s .c  o m*/
@Named("ScheduledCombinerHighPriorityExecutor")
private ScheduledExecutorService createScheduledCombinerHighPriorityExecutor(ServerConfig config) {
    int highPriorityTypeCount = config.getCombinerHighPriorityEventTypes().size();
    ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder().setDaemon(true);
    if (highPriorityTypeCount == 0) {
        return newSingleThreadScheduledExecutor(threadFactoryBuilder
                .setNameFormat("StoredObjectCombiner-High-Disabled-Should-Not-Be-Used").build());
    } else {
        return newScheduledThreadPool(highPriorityTypeCount,
                threadFactoryBuilder.setNameFormat("StoredObjectCombiner-High-%s").build());
    }
}