List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:org.kalaider.desktop.scheduler.runner.Runner.java
private static void runScheduler(Path configFilePath, String profile, int nThreads) throws Exception { Path libs = Paths.get("./lib"); Path plugins = Paths.get("./plugin"); LOG.log(Level.INFO, "Libraries found: {}.", Arrays.asList(getUrlsInDirectory(libs))); LOG.log(Level.INFO, "Plugins found: {}.", Arrays.asList(getUrlsInDirectory(plugins))); ClassLoader libsLoader = URLClassLoader.newInstance(getUrlsInDirectory(libs), Thread.currentThread().getContextClassLoader()); ClassLoader pluginsLoader = URLClassLoader.newInstance(getUrlsInDirectory(plugins), libsLoader); Thread newDaemon = new Thread(() -> { synchronized (lock) { Class<?> schedulerInstanceClass; try { schedulerInstanceClass = pluginsLoader .loadClass("org.kalaider.desktop.scheduler.SchedulerInstance"); } catch (ClassNotFoundException ex) { LOG.fatal("Class not found.", ex); return; }//from w w w .ja v a 2 s. c om Method getDefaultInstanceMethod; try { getDefaultInstanceMethod = schedulerInstanceClass.getMethod("getDefaultInstance", Path.class, String.class, int.class); } catch (NoSuchMethodException | SecurityException ex) { LOG.fatal("Method not found.", ex); return; } try { schedulerInstance = getDefaultInstanceMethod.invoke(null, configFilePath, profile, nThreads); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { LOG.fatal("Illegal method call.", ex); return; } Method startupMethod; try { startupMethod = schedulerInstanceClass.getMethod("startup"); } catch (NoSuchMethodException | SecurityException ex) { LOG.fatal("Method not found.", ex); return; } try { startupMethod.invoke(schedulerInstance); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { LOG.fatal("Illegal method call.", ex); return; } } }); newDaemon.setName("SchedulerRunnerThread"); newDaemon.setContextClassLoader(pluginsLoader); newDaemon.setDaemon(true); newDaemon.start(); }
From source file:org.alfresco.repo.transfer.fsr.FileTransferReceiver.java
public void commitAsync(final String transferId) throws TransferException { Lock lock = checkLock(transferId); Thread commitThread = new Thread(new Runnable() { @Override/* w w w .j ava2 s . c o m*/ public void run() { commit(transferId); } }); try { commitThread.setName("Transfer Commit Thread"); commitThread.setDaemon(true); progressMonitor.updateStatus(transferId, TransferProgress.Status.COMMIT_REQUESTED); } finally { lock.enableLockTimeout(); } commitThread.start(); }
From source file:org.apache.lens.driver.jdbc.JDBCDriver.java
/** * Inits the./*from w w w .j a v a2s.c o m*/ * * @throws LensException the lens exception */ public void init() throws LensException { final int maxPoolSize = parseInt(getConf().get(JDBC_POOL_MAX_SIZE.getConfigKey())); final int maxConcurrentQueries = parseInt( getConf().get(MaxConcurrentDriverQueriesConstraintFactory.MAX_CONCURRENT_QUERIES_KEY)); checkState(maxPoolSize >= maxConcurrentQueries, "maxPoolSize:" + maxPoolSize + " maxConcurrentQueries:" + maxConcurrentQueries); queryContextMap = new ConcurrentHashMap<>(); asyncQueryPool = Executors.newCachedThreadPool(new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread th = new Thread(runnable); th.setName("lens-driver-jdbc-" + THID.incrementAndGet()); return th; } }); Class<? extends ConnectionProvider> cpClass = getConf().getClass(JDBC_CONNECTION_PROVIDER, DataSourceConnectionProvider.class, ConnectionProvider.class); try { connectionProvider = cpClass.newInstance(); estimateConnectionProvider = cpClass.newInstance(); } catch (Exception e) { log.error("Error initializing connection provider: ", e); throw new LensException(e); } this.logSegregationContext = new MappedDiagnosticLogSegregationContext(); this.isStatementCancelSupported = getConf().getBoolean(STATEMENT_CANCEL_SUPPORTED, DEFAULT_STATEMENT_CANCEL_SUPPORTED); }
From source file:com.bt.download.android.gui.Librarian.java
public void syncMediaStore() { if (!isExternalStorageMounted()) { return;//from w w w. j a v a 2s. co m } Thread t = new Thread(new Runnable() { public void run() { syncMediaStoreSupport(); } }); t.setName("syncMediaStore"); t.setDaemon(true); t.start(); }
From source file:org.hyperic.hq.measurement.agent.server.ScheduleThread.java
private ThreadFactory getFactory(final String plugin) { final SecurityManager s = System.getSecurityManager(); final ThreadGroup group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); return new ThreadFactory() { private final AtomicLong num = new AtomicLong(); public Thread newThread(Runnable r) { final Thread rtn = new Thread(group, r); rtn.setDaemon(true);/*from w ww . ja va 2s.com*/ rtn.setName(plugin + "-" + num.getAndIncrement()); return rtn; } }; }
From source file:com.bt.download.android.gui.Librarian.java
public void syncApplicationsProvider() { if (!isExternalStorageMounted()) { return;//from ww w . ja v a2s .c om } Thread t = new Thread(new Runnable() { public void run() { syncApplicationsProviderSupport(); } }); t.setName("syncApplicationsProvider"); t.setDaemon(true); t.start(); }
From source file:org.languagetool.gui.LanguageToolSupport.java
private void init() { try {//from ww w .j a v a 2 s . c o m config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null); } catch (IOException ex) { throw new RuntimeException("Could not load configuration", ex); } Language defaultLanguage = config.getLanguage(); if (defaultLanguage == null) { defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault()); } /** * Warm-up: we have a lot of lazy init in LT, which causes the first check to * be very slow (several seconds) for languages with a lot of data and a lot of * rules. We just assume that the default language is the language that the user * often uses and init the LT object for that now, not just when it's first used. * This makes the first check feel much faster: */ reloadLanguageTool(defaultLanguage); checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); t.setName(t.getName() + "-lt-background"); return t; } }); check = new AtomicInteger(0); this.textComponent.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); recalculateSpans(e.getOffset(), e.getLength(), false); if (backgroundCheckEnabled) { checkDelayed(null); } } @Override public void removeUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); recalculateSpans(e.getOffset(), e.getLength(), true); if (backgroundCheckEnabled) { checkDelayed(null); } } @Override public void changedUpdate(DocumentEvent e) { mustDetectLanguage = config.getAutoDetect(); if (backgroundCheckEnabled) { checkDelayed(null); } } }); mouseListener = new MouseListener() { @Override public void mouseClicked(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { if (me.isPopupTrigger()) { showPopup(me); } } @Override public void mouseReleased(MouseEvent me) { if (me.isPopupTrigger()) { showPopup(me); } } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; this.textComponent.addMouseListener(mouseListener); actionListener = e -> _actionPerformed(e); mustDetectLanguage = config.getAutoDetect(); if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) { checkImmediately(null); } }
From source file:org.apache.nifi.cluster.coordination.http.replication.ThreadPoolRequestReplicator.java
/** * Creates an instance./*w ww. j a va2s. c o m*/ * * @param corePoolSize core size of the thread pool * @param maxPoolSize the max number of threads in the thread pool * @param maxConcurrentRequests maximum number of concurrent requests * @param client a client for making requests * @param clusterCoordinator the cluster coordinator to use for interacting with node statuses * @param connectionTimeout the connection timeout specified in milliseconds * @param readTimeout the read timeout specified in milliseconds * @param callback a callback that will be called whenever all of the responses have been gathered for a request. May be null. * @param eventReporter an EventReporter that can be used to notify users of interesting events. May be null. * @param nifiProperties properties */ public ThreadPoolRequestReplicator(final int corePoolSize, final int maxPoolSize, final int maxConcurrentRequests, final Client client, final ClusterCoordinator clusterCoordinator, final String connectionTimeout, final String readTimeout, final RequestCompletionCallback callback, final EventReporter eventReporter, final NiFiProperties nifiProperties) { if (corePoolSize <= 0) { throw new IllegalArgumentException("The Core Pool Size must be greater than zero."); } else if (maxPoolSize < corePoolSize) { throw new IllegalArgumentException("Max Pool Size must be >= Core Pool Size."); } else if (client == null) { throw new IllegalArgumentException("Client may not be null."); } this.client = client; this.clusterCoordinator = clusterCoordinator; this.connectionTimeoutMs = (int) FormatUtils.getTimeDuration(connectionTimeout, TimeUnit.MILLISECONDS); this.readTimeoutMs = (int) FormatUtils.getTimeDuration(readTimeout, TimeUnit.MILLISECONDS); this.maxConcurrentRequests = maxConcurrentRequests; this.responseMapper = new StandardHttpResponseMapper(nifiProperties); this.eventReporter = eventReporter; this.callback = callback; this.nifiProperties = nifiProperties; client.property(ClientProperties.CONNECT_TIMEOUT, connectionTimeoutMs); client.property(ClientProperties.READ_TIMEOUT, readTimeoutMs); client.property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE); final AtomicInteger threadId = new AtomicInteger(0); final ThreadFactory threadFactory = r -> { final Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); t.setName("Replicate Request Thread-" + threadId.incrementAndGet()); return t; }; executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); maintenanceExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override public Thread newThread(final Runnable r) { final Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); t.setName(ThreadPoolRequestReplicator.class.getSimpleName() + " Maintenance Thread"); return t; } }); maintenanceExecutor.scheduleWithFixedDelay(() -> purgeExpiredRequests(), 1, 1, TimeUnit.SECONDS); }
From source file:net.dv8tion.jda.entities.impl.TextChannelImpl.java
@Override public void sendFileAsync(File file, Message message, Consumer<Message> callback) { checkVerification();//from w w w .j av a2 s .c o m if (!checkPermission(getJDA().getSelfInfo(), Permission.MESSAGE_WRITE)) throw new PermissionException(Permission.MESSAGE_WRITE); if (!checkPermission(getJDA().getSelfInfo(), Permission.MESSAGE_ATTACH_FILES)) throw new PermissionException(Permission.MESSAGE_ATTACH_FILES); Thread thread = new Thread(() -> { Message messageReturn; try { messageReturn = sendFile(file, message); } catch (RateLimitedException e) { JDAImpl.LOG.warn("Got ratelimited when trying to upload file. Providing null to callback."); messageReturn = null; } if (callback != null) callback.accept(messageReturn); }); thread.setName("TextChannelImpl sendFileAsync Channel: " + id); thread.setDaemon(true); thread.start(); }
From source file:com.ibm.og.client.ApacheClient.java
@Override public ListenableFuture<Boolean> shutdown(final boolean immediate) { final SettableFuture<Boolean> future = SettableFuture.create(); final Thread t = new Thread(getShutdownRunnable(future, immediate)); t.setName("client-shutdown"); this.running = false; t.start();//ww w. ja v a 2 s . co m return future; }