Class ConcurrencyUtil
- Author:
- Eike Stepper
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckCancelation(IProgressMonitor monitor) static voidstatic ExecutorServicegetExecutorService(Object object) static ExecutorServicegetExecutorService(IManagedContainer container) static voidstatic voidRestores the interrupt status of the current thread when the directly caught exception is anInterruptedException.static voidsetThreadName(String name) static voidsetThreadName(Thread thread, String name) static voidsleep(long millis) static voidsleep(long millis, int nanos)
-
Method Details
-
sleep
public static void sleep(long millis) -
sleep
public static void sleep(long millis, int nanos) -
getExecutorService
- Since:
- 3.5
-
getExecutorService
- Since:
- 3.6
-
execute
- Since:
- 3.6
-
setThreadName
- Since:
- 3.8
-
setThreadName
- Since:
- 3.9
-
log
- Since:
- 3.9
-
checkCancelation
- Throws:
OperationCanceledException- Since:
- 3.13
-
restoreInterrupt
Restores the interrupt status of the current thread when the directly caught exception is anInterruptedException.Interruptible operations such as
Thread.sleep(long),Object.wait(),Thread.join(),CountDownLatch.await(), and interruptible queue or lock operations clear the current thread's interrupt status before throwingInterruptedException. This helper is intended for a broader catch boundary that cannot propagate that checked exception and instead translates it or otherwise terminates the current operation, when the surrounding thread-ownership and cancellation policy requires the status to remain observable.Callers must not use this as a blanket action for every broad catch, as a substitute for propagating
InterruptedException, or without analyzing continuing loops, retry logic, worker lifecycle code, ordinary-result translations, and intentional interrupt-consumption policies. Those contexts may require a different policy, because retaining the status can change subsequent waits, retries, shutdown behavior, or worker termination.Only the directly caught value is inspected. Causes are deliberately not traversed: a wrapper that merely contains an
InterruptedExceptiondoes not establish that this catch consumed the current thread's interrupt status, and restoring from a nested historical cause could spuriously interrupt unrelated execution.For a non-
InterruptedExceptionvalue this method does nothing. For anInterruptedExceptionit sets the current thread's interrupt status and otherwise leaves the supplied exception untouched. It does not throw, wrap, log, or inspect causes.- Parameters:
ex- the exception directly caught by the caller- Since:
- 3.31
-