public class ThreadUtil
extends java.lang.Object
Constructor | Description |
---|---|
ThreadUtil() |
Modifier and Type | Method | Description |
---|---|---|
static <T> T |
cleanContextExceptionExecute(java.lang.ClassLoader contextLoader,
java.util.concurrent.Callable<T> callable) |
Stupid...
|
static <T> T |
cleanContextExceptionExecute(java.util.concurrent.Callable<T> callable) |
Short version of
cleanContextExceptionExecute(ClassLoader, Callable) passing in null
as context class loader. |
static <T> T |
cleanContextExecute(java.lang.ClassLoader contextLoader,
java.util.concurrent.Callable<T> callable) |
Execute a callable with a clean thread context and security context as
to avoid any passing on of thread context and security context to another
thread that may be spawned from here and may end up holding copies in the end.
|
static <T> T |
cleanContextExecute(java.util.concurrent.Callable<T> callable) |
Short version of
cleanContextExecute(ClassLoader, Callable) passing in null
as context class loader. |
static <T,E extends java.lang.Exception> |
cleanContextGet(ThrowingSupplier<T,E> supplier) |
Variation of
cleanContextExceptionExecute(Callable) that relies on ThrowingSupplier to
generically limit the amount of noise due to missing exception interference. |
static <T,E extends java.lang.Exception> |
cleanContextGet(java.lang.ClassLoader contextLoader,
ThrowingSupplier<T,E> supplier) |
Variation of
cleanContextExceptionExecute(ClassLoader, Callable) that relies on ThrowingSupplier to
generically limit the amount of noise due to missing exception interference. |
static <E extends java.lang.Exception> |
cleanContextRun(ThrowingRunnable<E> run) |
Short version of
#cleanContextRun(ClassLoader, Runnable) passing in null
as context class loader. |
static <E extends java.lang.Exception> |
cleanContextRun(java.lang.ClassLoader contextLoader,
ThrowingRunnable<E> run) |
Execute a
ThrowingRunnable with a clean thread context and security context as
to avoid any passing on of thread context and security context to another
thread that may be spawned from here and may end up holding copies in the end. |
static <T> T |
cleanContextSupply(java.lang.ClassLoader contextLoader,
java.util.function.Supplier<T> supplier) |
Execute a
Supplier with a clean thread context and security context as
to avoid any passing on of thread context and security context to another
thread that may be spawned from here and may end up holding copies in the end. |
static <T> T |
cleanContextSupply(java.util.function.Supplier<T> supplier) |
Short version of
cleanContextSupply(ClassLoader, Supplier) passing in null
as context class loader. |
static <T,E extends java.lang.Exception> |
confine(java.util.concurrent.Callable<T> call,
java.lang.Class<E> eclz) |
Using this method, an invocation of a callable may be wrapped to only throw a declared
checked exception.
|
public static <T> T cleanContextExceptionExecute(java.lang.ClassLoader contextLoader, java.util.concurrent.Callable<T> callable) throws java.lang.Exception
Execute a callable with a clean thread context and security context as to avoid any passing on of thread context and security context to another thread that may be spawned from here and may end up holding copies in the end. Any exception thrown will be propagated.
See also confine(Callable, Class)
.
contextLoader
- A class loader to set as context class loadercallable
- A Callable
to invokeCallable
invocationjava.lang.Exception
public static <T> T cleanContextExceptionExecute(java.util.concurrent.Callable<T> callable) throws java.lang.Exception
cleanContextExceptionExecute(ClassLoader, Callable)
passing in null
as context class loader.callable
- A Callable
to invokeCallable
invocationjava.lang.Exception
public static <T> T cleanContextExecute(java.lang.ClassLoader contextLoader, java.util.concurrent.Callable<T> callable)
contextLoader
- A class loader to set as context class loadercallable
- A Callable
to invokeCallable
invocationpublic static <T> T cleanContextExecute(java.util.concurrent.Callable<T> callable)
cleanContextExecute(ClassLoader, Callable)
passing in null
as context class loader.callable
- A Callable
to invokeCallable
invocationpublic static <T> T cleanContextSupply(java.lang.ClassLoader contextLoader, java.util.function.Supplier<T> supplier)
Supplier
with a clean thread context and security context as
to avoid any passing on of thread context and security context to another
thread that may be spawned from here and may end up holding copies in the end.contextLoader
- A class loader to set as context class loadersupplier
- A Supplier
to invokeSupplier
invocationpublic static <T> T cleanContextSupply(java.util.function.Supplier<T> supplier)
cleanContextSupply(ClassLoader, Supplier)
passing in null
as context class loader.supplier
- A Supplier
to invokeSupplier
invocationpublic static <T,E extends java.lang.Exception> T confine(java.util.concurrent.Callable<T> call, java.lang.Class<E> eclz) throws E extends java.lang.Exception
RuntimeException
, this exception will be rethrown. RuntimeException
This is handy when it is required to pass a callable given an execution that potentially throws a check exception that
is much narrower in scope than simply Exception
.
For example given a method readTable
that throws a SQLException
, an equivalent execution using
cleanContextExceptionExecute(Callable)
looks like this:
confine(()->cleanContextExceptionExecute(this::readTable),SQLException.class);
eclz
- the confinement exceptioncall
- the Callable
to invokeCallable
invocationE
- A confinement exceptionE extends java.lang.Exception
public static <T,E extends java.lang.Exception> T cleanContextGet(java.lang.ClassLoader contextLoader, ThrowingSupplier<T,E> supplier) throws E extends java.lang.Exception
cleanContextExceptionExecute(ClassLoader, Callable)
that relies on ThrowingSupplier
to
generically limit the amount of noise due to missing exception interference. In many places using lambdas this approach
is syntactically nicer than using confineE extends java.lang.Exception
public static <T,E extends java.lang.Exception> T cleanContextGet(ThrowingSupplier<T,E> supplier) throws E extends java.lang.Exception
cleanContextExceptionExecute(Callable)
that relies on ThrowingSupplier
to
generically limit the amount of noise due to missing exception interference. In many places using lambdas this approach
is syntactically nicer than using confineE extends java.lang.Exception
public static <E extends java.lang.Exception> void cleanContextRun(java.lang.ClassLoader contextLoader, ThrowingRunnable<E> run) throws E extends java.lang.Exception
ThrowingRunnable
with a clean thread context and security context as
to avoid any passing on of thread context and security context to another
thread that may be spawned from here and may end up holding copies in the end.contextLoader
- A class loader to set as context class loaderrun
- A Runnable
to invokeE extends java.lang.Exception
public static <E extends java.lang.Exception> void cleanContextRun(ThrowingRunnable<E> run) throws E extends java.lang.Exception
#cleanContextRun(ClassLoader, Runnable)
passing in null
as context class loader.run
- A Runnable
to invokeE extends java.lang.Exception