Skip to content

Instantly share code, notes, and snippets.

@bademux
Created January 28, 2021 11:58
Show Gist options
  • Save bademux/bfaf2f414a49810bb7fc41205fe652ee to your computer and use it in GitHub Desktop.
Save bademux/bfaf2f414a49810bb7fc41205fe652ee to your computer and use it in GitHub Desktop.
Run task in current thread. Handy for testing. How it works: when thread factory returns null, ThreadPoolExecutor invokes CallerRunsPolicy
@UtilityClass
public class ExecutorUtils {
public static ExecutorService currentThreadExecutorService() {
return new ThreadPoolExecutor(0, 1, 0L, SECONDS, new SynchronousQueue<>(), r -> null, new CallerRunsPolicy());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment