/** * 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; }
/** * 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; }
/** * 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; }
public void testPlatformThreadFactory_default() { ThreadFactory factory = MoreExecutors.platformThreadFactory(); assertNotNull(factory); // Executors#defaultThreadFactory() may return a new instance each time. assertEquals(factory.getClass(), Executors.defaultThreadFactory().getClass()); }
@Override public void execute(Runnable command) { Thread thread = MoreExecutors.platformThreadFactory().newThread(command); thread.setDaemon(true); thread.setName(serviceName()); thread.start(); } };
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; } }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; }
/** * Creates a thread using {@link #platformThreadFactory}, and sets its name to {@code name} * unless changing the name is forbidden by the security manager. */ 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; }
/** * Get a {@link ThreadFactory} suitable for use in the current environment. * @param nameFormat to apply to threads created by the factory. * @param daemon {@code true} if the threads the factory creates are daemon threads, {@code false} * otherwise. * @return a {@link ThreadFactory}. */ public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon) { if (IS_RESTRICTED_APPENGINE) { @SuppressWarnings("BetaApi") ThreadFactory factory = MoreExecutors.platformThreadFactory(); return factory; } else { return new ThreadFactoryBuilder() .setDaemon(daemon) .setNameFormat(nameFormat) .build(); } }
/** * Get a {@link ThreadFactory} suitable for use in the current environment. * * @param nameFormat to apply to threads created by the factory. * @param daemon {@code true} if the threads the factory creates are daemon threads, * {@code false} otherwise. * @return a {@link ThreadFactory}. */ public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon) { ThreadFactory threadFactory = MoreExecutors.platformThreadFactory(); return new ThreadFactoryBuilder() .setThreadFactory(threadFactory) .setDaemon(daemon) .setNameFormat(nameFormat) .build(); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Get a {@link ThreadFactory} suitable for use in the current environment. * @param nameFormat to apply to threads created by the factory. * @param daemon {@code true} if the threads the factory creates are daemon threads, {@code false} * otherwise. * @return a {@link ThreadFactory}. */ public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon) { if (PlatformInformation.isOnGAEStandard7()) { return MoreExecutors.platformThreadFactory(); } else { return new ThreadFactoryBuilder() .setDaemon(daemon) .setNameFormat(nameFormat) .build(); } } }
/** * overridden in order to set the UncaughtExceptionHandler on the Thread that is created to run the ScannerSession */ @Override protected Executor executor() { return command -> { String name = serviceName(); Preconditions.checkNotNull(name); Preconditions.checkNotNull(command); Thread result = MoreExecutors.platformThreadFactory().newThread(command); try { result.setName(name); result.setUncaughtExceptionHandler(uncaughtExceptionHandler); } catch (SecurityException e) { // OK if we can't set the name in this environment. } result.start(); }; }
public void testPlatformThreadFactory_default() { ThreadFactory factory = MoreExecutors.platformThreadFactory(); assertNotNull(factory); // Executors#defaultThreadFactory() may return a new instance each time. assertEquals(factory.getClass(), Executors.defaultThreadFactory().getClass()); }