public class SignalUtil extends Object
This can help diagnose deadlocks by identifying the threads involved.
Modifier and Type | Field and Description |
---|---|
static long |
SIGNAL_LOG_INTERVAL_SECONDS |
static long |
SIGNAL_LOG_QUIESCE_TIMEOUT_MINUTES |
Constructor and Description |
---|
SignalUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
aquire(Semaphore sem,
String callerClass,
String callerMethod,
Object... args)
Implements the same semantics as
Semaphore.acquire() , except that the wait will
periodically time out within this method to log a warning message that the thread appears
stuck. |
static void |
await(CountDownLatch latch,
String callerClass,
String callerMethod,
Object... args)
Implements the same semantics as
CountDownLatch.await() , except that the wait will
periodically time out within this method to log a warning message that the thread appears
stuck. |
static <T> T |
get(Future<T> future,
String callerClass,
String callerMethod,
Object... args)
Implements the same semantics as
Future.get() , except that the wait will periodically
time out within this method to log a warning message that the thread appears stuck. |
static void |
lock(Lock lock,
String callerClass,
String callerMethod,
Object... args)
Implements the same semantics as
Lock.lock() , except that the wait will periodically
time out within this method to log a warning message that the thread appears stuck. |
static <T> Future<T> |
take(CompletionService<T> cs,
String callerClass,
String callerMethod,
Object... args)
Implements the same semantics as
CompletionService.take() , except that the wait will
periodically time out within this method to log a warning message that the thread appears
stuck. |
public static final long SIGNAL_LOG_INTERVAL_SECONDS
public static final long SIGNAL_LOG_QUIESCE_TIMEOUT_MINUTES
public static void lock(Lock lock, String callerClass, String callerMethod, Object... args)
Lock.lock()
, except that the wait will periodically
time out within this method to log a warning message that the thread appears stuck. This
cycle will be repeated until the lock is obtained. If the thread has waited for an extended
period, then wait logging is quiesced to avoid overwhelming the logs. If and when a thread
that has been reported as being stuck finally does obtain the lock, then a warning level
message is logged to indicate that the thread is resuming.lock
- the Lock object to wait oncallerClass
- the caller classcallerMethod
- the caller methodargs
- extra arguments to be appended to the log messagepublic static <T> Future<T> take(CompletionService<T> cs, String callerClass, String callerMethod, Object... args) throws InterruptedException
CompletionService.take()
, except that the wait will
periodically time out within this method to log a warning message that the thread appears
stuck. This cycle will be repeated until a Future
is obtained. If the thread has
waited for an extended period, then wait logging is quiesced to avoid overwhelming the logs.
If and when a thread that has been reported as being stuck finally does obtain a
Future
, then a warning level message is logged to indicate that the thread is
resuming.T
- Generic type of the Future resultcs
- the CompletionService to wait oncallerClass
- the caller classcallerMethod
- the caller methodargs
- extra arguments to be appended to the log messageInterruptedException
public static void await(CountDownLatch latch, String callerClass, String callerMethod, Object... args) throws InterruptedException
CountDownLatch.await()
, except that the wait will
periodically time out within this method to log a warning message that the thread appears
stuck. This cycle will be repeated until the latch has counted down to zero. If the thread
has waited for an extended period, then wait logging is quiesced to avoid overwhelming the
logs. If and when a thread that has been reported as being stuck and the latch is finally
counted down to zero, then a warning level message is logged to indicate that the thread is
resuming.latch
- the CountDownLatch object to wait oncallerClass
- the caller classcallerMethod
- the caller methodargs
- extra arguments to be appended to the log messageInterruptedException
public static <T> T get(Future<T> future, String callerClass, String callerMethod, Object... args) throws InterruptedException, ExecutionException
Future.get()
, except that the wait will periodically
time out within this method to log a warning message that the thread appears stuck. This
cycle will be repeated until the result is available. If the thread has waited for an extended
period, then wait logging is quiesced to avoid overwhelming the logs. If and when a thread
that has been reported as being stuck finally does obtain the result, then a warning level
message is logged to indicate that the thread is resuming.T
- Generic for the type of the resultfuture
- the Future to obtain the result fromcallerClass
- the caller classcallerMethod
- the caller methodargs
- extra arguments to be appended to the log messageInterruptedException
ExecutionException
public static void aquire(Semaphore sem, String callerClass, String callerMethod, Object... args) throws InterruptedException
Semaphore.acquire()
, except that the wait will
periodically time out within this method to log a warning message that the thread appears
stuck. This cycle will be repeated until the semaphore is acquired. If the thread has waited
for an extended period, then wait logging is quiesced to avoid overwhelming the logs. If and
when a thread that has been reported as being stuck and the semaphore is finally acquired,
then a warning level message is logged to indicate that the thread is resuming.sem
- the semaphore to wait oncallerClass
- the caller classcallerMethod
- the caller methodargs
- extra arguments to be appended to the log messageInterruptedException
Copyright © 2011-2015 IBM. All Rights Reserved.