List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder setNameFormat
public ThreadFactoryBuilder setNameFormat(String nameFormat)
From source file:emily.event.JDAEventManager.java
public JDAEventManager(DiscordBot bot) { ThreadFactoryBuilder threadBuilder = new ThreadFactoryBuilder(); threadBuilder.setNameFormat(String.format("shard-%02d-command-%%d", bot.getShardId())); this.threadExecutor = (ThreadPoolExecutor) Executors.newCachedThreadPool(threadBuilder.build()); this.bot = bot; }
From source file:org.metaservice.kryo.KryoClientUtil.java
public Client startClient(Listener listener) throws IOException { int size1 = 31457280; int size2 = 180000; LOGGER.info("Starting Client with sizes {}/{}", size1, size2); Client client = new Client(size1, size2); new KryoInitializer().initialize(client.getKryo()); ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setNameFormat("threaded_listener_thread_%d"); client.addListener(/*from w ww. j av a 2 s.c om*/ new Listener.ThreadedListener(listener, Executors.newSingleThreadExecutor(builder.build()))); client.start(); int timeout = 5000; int retries = 0; while (!client.isConnected()) { try { client.connect(timeout, "127.0.0.1", 54555/*, 54777*/); retries++; } catch (IOException e) { if (retries > 10) { LOGGER.error("stopping to retry ", e); throw e; } else { try { LOGGER.info("connection failed, retrying in 3 seconds"); Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } } } } return client; }
From source file:org.openecomp.sdc.be.components.distribution.engine.NotificationExecutorService.java
public ExecutorService createExcecutorService( DistributionNotificationTopicConfig distributionNotificationTopic) { Integer minThreadPoolSize = distributionNotificationTopic.getMinThreadPoolSize(); if (minThreadPoolSize == null) { minThreadPoolSize = 0;// w w w .j a va 2 s .c om } Integer maxThreadPoolSize = distributionNotificationTopic.getMaxThreadPoolSize(); if (maxThreadPoolSize == null) { maxThreadPoolSize = 10; } ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder(); threadFactoryBuilder.setNameFormat("distribution-notification-thread-%d"); ThreadFactory threadFactory = threadFactoryBuilder.build(); ExecutorService executorService = new ThreadPoolExecutor(minThreadPoolSize, maxThreadPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory); return executorService; }
From source file:talkeeg.common.ipc.IpcServiceImpl.java
IpcServiceImpl(IpcServiceManager serviceManager) { this.sm = serviceManager; final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true);/*from w ww. ja va 2 s .c o m*/ builder.setNameFormat(getClass().getSimpleName() + "-pool-%d"); this.executor = Executors.newCachedThreadPool(builder.build()); this.messageProcessor = this.sm.messageProcessor; this.whirligig = new Whirligig(this.sm.config, this.sm.ioProcessor, this); }
From source file:com.kolich.curacao.util.AsyncServletExecutorServiceFactory.java
public final ExecutorService build() { final ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); if (threadNameFormat_ != null) { builder.setNameFormat(threadNameFormat_); }//from w w w. ja v a2 s. co m if (priority_ != null) { builder.setPriority(priority_); } if (useDaemon_ != null) { builder.setDaemon(useDaemon_); } return (size_ > 0) ? // Fixed sized thread pool (no more than N-threads). newFixedThreadPool(size_, builder.build()) : // Unbounded thread pool, will grow as needed. newCachedThreadPool(builder.build()); }
From source file:com.alibaba.wasp.master.BulkAssigner.java
/** * Run the bulk assign./*w ww.j a v a 2 s . c om*/ * * @param sync * Whether to assign synchronously. * @throws InterruptedException * @return True if done. * @throws java.io.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 entityGroups-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; }
From source file:org.apache.hadoop.hbase.master.BulkAssigner.java
/** * Run the bulk assign./*from ww w . j a v a 2s. com*/ * * @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; }
From source file:com.notifier.desktop.ApplicationModule.java
@Override protected void configure() { bind(Application.class); bind(SwtManager.class).to(SwtManagerImpl.class); bind(TrayManager.class).to(SwtTrayManager.class); bind(PreferencesDialog.class); bind(NotificationManager.class).to(NotificationManagerImpl.class); bind(new TypeLiteral<NotificationParser<byte[]>>() { }).to(MultiNotificationParser.class); bind(DeviceManager.class).to(DeviceManagerImpl.class); bind(NotificationBroadcaster.class).annotatedWith(Tray.class).to(TrayNotificationBroadcaster.class); bind(NotificationBroadcaster.class).annotatedWith(Growl.class).to(GrowlNotificationBroadcaster.class); bind(NotificationBroadcaster.class).annotatedWith(Libnotify.class) .to(LibnotifyNotificationBroadcaster.class); bind(InstantMessagingNotificationBroadcaster.class).annotatedWith(Msn.class) .to(MsnNotificationBroadcaster.class); bind(WifiTransport.class).to(NioWifiTransport.class); bind(BluetoothTransport.class).to(BluetoothTransportImpl.class); bind(UsbTransport.class).to(UsbTransportImpl.class); bind(UsbPortClient.class); bind(NetworkManager.class).to(NetworkManagerImpl.class); bind(UpnpManager.class).to(UpnpManagerImpl.class); bind(UpdateManager.class).to(UpdateManagerImpl.class); bind(ServiceServer.class).to(ServiceServerImpl.class); bind(OperatingSystemProcessManager.class).to(OperatingSystemProcessManagerImpl.class); ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder(); threadFactoryBuilder.setNameFormat("task-%s"); threadFactoryBuilder.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override//from w w w . j a v a2 s.co m public void uncaughtException(Thread t, Throwable e) { logger.error("Uncaught exception", e); } }); ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4, threadFactoryBuilder.build()); bind(ExecutorService.class).toInstance(executorService); bind(ScheduledExecutorService.class).toInstance(executorService); }
From source file:org.jmangos.commons.threadpool.CommonThreadPoolManager.java
/** * @see org.jmangos.commons.service.Service#start() */// w ww . j a va2s . co m @PostConstruct @Override public void start() { final int scheduledPoolSize = ThreadPoolConfig.GENERAL_POOL; this.scheduledPool = new ScheduledThreadPoolExecutor(scheduledPoolSize); final ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setNameFormat("JMaNGOS-scheduled-pool-%d"); this.scheduledPool.setThreadFactory(tfb.build()); this.scheduledPool.prestartAllCoreThreads(); tfb.setNameFormat("JMaNGOS-instant-pool-%d"); final int instantPoolSize = ThreadPoolConfig.GENERAL_POOL; this.instantPool = new ThreadPoolExecutor(instantPoolSize, instantPoolSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100000)); this.instantPool.setThreadFactory(tfb.build()); this.instantPool.prestartAllCoreThreads(); }
From source file:org.jdag.node.NodeExecutor.java
/** * CTOR/* w ww . ja v a2 s . c o m*/ */ @Inject public NodeExecutor(Communicator communicator, NodeConfig config) { myCommunicator = communicator; myConfig = config; myPaceMaker = new PaceMaker(); ThreadFactoryBuilder tfBuilder = new ThreadFactoryBuilder(); ThreadFactory namedFactory = tfBuilder.setNameFormat(NodeExecutor.class.getSimpleName()).build(); myExecutorService = Executors.newFixedThreadPool(2, namedFactory); ThreadFactory namedSchedulerFactory = tfBuilder.setNameFormat(NodeExecutor.class.getSimpleName() + " sch") .build(); myScheduler = Executors.newScheduledThreadPool(2, namedSchedulerFactory); myExecutionContext = new SimpleExecutionContext(); myFuncToExecutionStatusMap = new HashMap<VertexID, Future<ExecutionResult>>(); }