return new InstrumentedThreadFactory(Executors.privilegedThreadFactory(), registry);
return new InstrumentedThreadFactory(Executors.privilegedThreadFactory(), registry, name);
public static ThreadFactory privilegedThreadFactory() { return Executors.privilegedThreadFactory(); }
/** * {@inheritDoc} */ public ExecutorService newThreadPool() { return Executors.newCachedThreadPool( Executors.privilegedThreadFactory()); } }
/** * {@inheritDoc} */ public ExecutorService newThreadPool() { return Executors.newCachedThreadPool( Executors.privilegedThreadFactory()); } }
public ThreadFactory build() { //TODO find better ThreadFactory if (deamon) { return Executors.privilegedThreadFactory(); } return Executors.defaultThreadFactory(); } }
/** * {@inheritDoc} */ public ExecutorService newThreadPool() { return Executors.newCachedThreadPool( Executors.privilegedThreadFactory()); } }
/** * return an instance to the thread factory used to create new executor services */ private static ThreadFactory getThreadFactory(final String nameFormat) { final ThreadFactory defaultThreadFactory = Executors.privilegedThreadFactory(); return new ThreadFactory() { final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null; @Override public Thread newThread(Runnable runnable) { Thread thread = defaultThreadFactory.newThread(runnable); if (nameFormat != null) { thread.setName(String.format(nameFormat, count.getAndIncrement())); } return thread; } }; }
@PostConstruct public void initTreadManagerFactory() { if (managedThreadFactory != null) { threadFactory = managedThreadFactory; LOGGER.info("### Managed Thread Factory used ###"); } else { threadFactory = Executors.privilegedThreadFactory(); LOGGER.info("### Privilleged Thread Factory used ###"); } }
/** * Constructs a new {@code Thread}. Implementations may also initialize * priority, name, daemon status, {@code ThreadGroup}, etc. * * @param r a runnable to be executed by new thread instance * @return constructed thread, or {@code null} if the request to * create a thread is rejected */ @Override public Thread newThread(Runnable r) { Thread thread = Executors.privilegedThreadFactory().newThread(r); thread.setName(this.threadNamePrefix + nextThreadID()); thread.setPriority(this.priority); thread.setDaemon(this.isDaemon); return thread; }
return new InstrumentedThreadFactory(Executors.privilegedThreadFactory(), registry);
return new InstrumentedThreadFactory(Executors.privilegedThreadFactory(), registry, name);
@Override public void upgrade() throws Exception { int numThreads = cConf.getInt(Constants.Upgrade.UPGRADE_THREAD_POOL_SIZE); ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactoryBuilder() // all the threads should be created as 'cdap' .setThreadFactory(Executors.privilegedThreadFactory()) .setNameFormat("dataset-upgrader-%d") .setDaemon(true) .build()); try { // Upgrade system dataset upgradeSystemDatasets(executor); // Upgrade all user hbase tables upgradeUserTables(executor); } finally { // We'll have tasks pending in the executor only on an interrupt, when user wants to abort the upgrade. // Use shutdownNow() to interrupt the tasks and abort. executor.shutdownNow(); } }
new ThreadFactoryBuilder() .setThreadFactory(Executors.privilegedThreadFactory()) .setNameFormat("hbase-queue-upgrader-%d") .setDaemon(true)