/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ @GwtIncompatible // concurrency static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. Otherwise, * returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta @GwtIncompatible // concurrency public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) {
checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) {
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ @GwtIncompatible // concurrency static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. Otherwise, * returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta @GwtIncompatible // concurrency public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) {
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. Otherwise, * returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta @GwtIncompatible // concurrency public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) {
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ @GwtIncompatible // concurrency static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) {
checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) {
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Creates an {@link ExecutorService} that renames the {@link Thread threads} that its tasks run * in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * @param service The executor to decorate * @param nameSupplier The source of names for each task */ static ExecutorService renamingDecorator(final ExecutorService service, final Supplier<String> nameSupplier) { checkNotNull(service); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try. return service; } return new WrappingExecutorService(service) { @Override protected <T> Callable<T> wrapTask(Callable<T> callable) { return Callables.threadRenaming(callable, nameSupplier); } @Override protected Runnable wrapTask(Runnable command) { return Callables.threadRenaming(command, nameSupplier); } }; }
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in. * * <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed * right before each task is run. The renaming is best effort, if a {@link SecurityManager} * prevents the renaming then it will be skipped but the tasks will still execute. * * @param executor The executor to decorate * @param nameSupplier The source of names for each task */ static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) { checkNotNull(executor); checkNotNull(nameSupplier); if (isAppEngine()) { // AppEngine doesn't support thread renaming, so don't even try return executor; } return new Executor() { @Override public void execute(Runnable command) { executor.execute(Callables.threadRenaming(command, nameSupplier)); } }; }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. * Otherwise, returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. * Otherwise, returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }