public Notifier(String service) { super.setDaemon(true); super.setName("DubboRedisSubscribe"); this.service = service; }
public Notifier(String service) { super.setDaemon(true); super.setName("DubboRedisSubscribe"); this.service = service; }
@Override public Thread newThread(Runnable r) { Thread t = delegate.newThread(r); t.setName(name + " [#" + threadNum.incrementAndGet() + "]"); return t; }
/** Create a thread and start the monitor. */ public ServerMonitor(int _port, Vector _oosList) { port = _port; oosList = _oosList; keepRunning = true; monitorThread = new Thread(this); monitorThread.setDaemon(true); monitorThread.setName("SocketHubAppender-Monitor-" + port); monitorThread.start(); }
@Override public Thread newThread(Runnable runnable) { Thread thread = backingThreadFactory.newThread(runnable); if (nameFormat != null) { thread.setName(format(nameFormat, count.getAndIncrement())); } if (daemon != null) { thread.setDaemon(daemon); } if (priority != null) { thread.setPriority(priority); } if (uncaughtExceptionHandler != null) { thread.setUncaughtExceptionHandler(uncaughtExceptionHandler); } return thread; } };
private void drainQueue() throws Exception { for (HttpUrl url; (url = queue.take()) != null; ) { if (!fetchedUrls.add(url)) { continue; } Thread currentThread = Thread.currentThread(); String originalName = currentThread.getName(); currentThread.setName("Crawler " + url.toString()); try { fetch(url); } catch (IOException e) { System.out.printf("XXX: %s %s%n", url, e); } finally { currentThread.setName(originalName); } } }
@Override public void run() { Thread t = Thread.currentThread(); String name = t.getName(); ClassLoader cl = t.getContextClassLoader(); try { r.run(); } finally { t.setName(name); t.setContextClassLoader(cl); } } };
@Override public V call() throws Exception { Thread t = Thread.currentThread(); String name = t.getName(); ClassLoader cl = t.getContextClassLoader(); try { return r.call(); } finally { t.setName(name); t.setContextClassLoader(cl); } } };
private static <T> Future<T> executeInNewThread(String threadName, Callable<T> callable) { FutureTask<T> task = new FutureTask<>(callable); Thread thread = new Thread(task); thread.setName(threadName); thread.setDaemon(true); thread.start(); return task; } }
/** Tries to set name of the given {@link Thread}, returns true if successful. */ @GwtIncompatible // threads private static boolean trySetName(final String threadName, Thread currentThread) { // In AppEngine, this will always fail. Should we test for that explicitly using // MoreExecutors.isAppEngine? More generally, is there a way to see if we have the modifyThread // permission without catching an exception? try { currentThread.setName(threadName); return true; } catch (SecurityException e) { return false; } } }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} unless * changing the name is forbidden by the security manager. */ @GwtIncompatible // concurrency static Thread newThread(String name, Runnable runnable) { checkNotNull(name); checkNotNull(runnable); Thread result = platformThreadFactory().newThread(runnable); try { result.setName(name); } catch (SecurityException e) { // OK if we can't set the name in this environment. } return result; }
static void updateThreadName(Request data) { String name = data.getName(); StringBuilder builder = NAME_BUILDER.get(); builder.ensureCapacity(Utils.THREAD_PREFIX.length() + name.length()); builder.replace(Utils.THREAD_PREFIX.length(), builder.length(), name); Thread.currentThread().setName(builder.toString()); }
public static void check(final IUpdateCallback callback) { Runnable run = () -> { try { Release release = checkForNewRelease(); if (release != null) { callback.onUpdate(release); } } catch (Exception e) { LOG.debug("Jadx update error", e); } }; Thread thread = new Thread(run); thread.setName("Jadx update thread"); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); }
@Override public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setName(THREAD_NAME); thread.setPriority(THREAD_PRIORITY); thread.setDaemon(THREAD_DAEMON); thread.setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER); return thread; } };
@Override public void onShutdown() { Thread.currentThread().setName(oldName); } }
@Override public void onStart() { final Thread currentThread = Thread.currentThread(); oldName = currentThread.getName(); currentThread.setName(name); }
@Test public void theTest() throws Exception { AtomicInteger seq = new AtomicInteger(); Thread threadA = new Thread(() -> threadA(seq)); threadA.setName("Thread-A"); Thread threadB = new Thread(() -> threadB(seq)); threadB.setName("Thread-B"); threadA.start(); threadB.start(); threadA.join(20 * 1000); threadB.join(20 * 1000); }