Example usage for java.lang Thread.State equals

List of usage examples for java.lang Thread.State equals

Introduction

In this page you can find the example usage for java.lang Thread.State equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:Main.java

/**
 * Check whether a specific thread is running (or able to run) right now.
 *
 * @param t the thread to check/*from w  ww . j  a  v a2 s . co m*/
 * @return true is the specified thread is or could be running right now
 */
static public boolean canThreadRun(@Nonnull Thread t) {
    Thread.State s = t.getState();
    return s.equals(Thread.State.RUNNABLE);
}

From source file:Main.java

/**
 * Check whether a specific thread is currently waiting.
 * <p>/*from w w  w.  j  a v a  2 s .  c  om*/
 * Note: This includes both waiting due to an explicit wait() call, and due
 * to being blocked attempting to synchronize.
 * <p>
 * Note: {@link #canThreadRun(Thread)} and {@link #isThreadWaiting(Thread)}
 * should never simultaneously be true, but it might look that way due to
 * sampling delays when checking on another thread.
 *
 * @param t the thread to check
 * @return true is the specified thread is or could be running right now
 */
static public boolean isThreadWaiting(@Nonnull Thread t) {
    Thread.State s = t.getState();
    return s.equals(Thread.State.BLOCKED) || s.equals(Thread.State.WAITING)
            || s.equals(Thread.State.TIMED_WAITING);
}

From source file:org.apache.synapse.commons.jmx.ThreadingView.java

private boolean isBlocked(ThreadInfo threadInfo) {
    // A thread is considered "Blocked" if it is in the BLOCKED state
    // or if it is in the WAITING state due to some reason other than
    // 'parking'.
    Thread.State state = threadInfo.getThreadState();
    if (state.equals(Thread.State.BLOCKED)) {
        return true;
    } else if (state.equals(Thread.State.WAITING) || state.equals(Thread.State.TIMED_WAITING)) {
        StackTraceElement[] stackTrace = threadInfo.getStackTrace();
        if (stackTrace.length > 0 && !"park".equals(stackTrace[0].getMethodName())) {
            return true;
        }/*from  w w w . j  a  v a2 s .  c o  m*/
    }

    return false;
}