Tabnine Logo
Thread.getState
Code IndexAdd Tabnine to your IDE (free)

How to use
getState
method
in
java.lang.Thread

Best Java code snippets using java.lang.Thread.getState (Showing top 20 results out of 2,817)

origin: netty/netty

@Override
public State state() {
  return t.getState();
}
origin: redisson/redisson

@Override
public State state() {
  return t.getState();
}
origin: google/guava

boolean isWaiting(Thread thread) {
 switch (thread.getState()) {
  case BLOCKED:
  case WAITING:
  case TIMED_WAITING:
   return true;
  default:
   return false;
 }
}
origin: Alluxio/alluxio

/**
 * @param thread a thread
 * @return a human-readable representation of the thread's stack trace
 */
public static String formatStackTrace(Thread thread) {
 Throwable t = new Throwable(String.format("Stack trace for thread %s (State: %s):",
   thread.getName(), thread.getState()));
 t.setStackTrace(thread.getStackTrace());
 StringWriter sw = new StringWriter();
 t.printStackTrace(new PrintWriter(sw));
 return sw.toString();
}
origin: neo4j/neo4j

public Thread.State state()
{
  return thread.getState();
}
origin: google/guava

static void awaitWaiting(Thread t) {
 while (true) {
  Thread.State state = t.getState();
  switch (state) {
   case RUNNABLE:
   case BLOCKED:
    Thread.yield();
    break;
   case WAITING:
    return;
   default:
    throw new AssertionError("unexpected state: " + state);
  }
 }
}
origin: google/guava

/** Wait for the given thread to reach the {@link State#TIMED_WAITING} thread state. */
void awaitTimedWaiting(Thread thread) {
 while (true) {
  switch (thread.getState()) {
   case BLOCKED:
   case NEW:
   case RUNNABLE:
   case WAITING:
    Thread.yield();
    break;
   case TIMED_WAITING:
    return;
   case TERMINATED:
   default:
    throw new AssertionError();
  }
 }
}
origin: google/guava

private static void awaitBlockedOn(Thread t, Object blocker) throws InterruptedException {
 while (!isThreadBlockedOn(t, blocker)) {
  if (t.getState() == Thread.State.TERMINATED) {
   throw new RuntimeException("Thread " + t + " exited unexpectedly");
  }
  Thread.sleep(1);
 }
}
origin: neo4j/neo4j

@Override
public boolean test( Thread thread )
{
  State threadState = thread.getState();
  seenStates.add( threadState );
  return possibleStates.contains( threadState );
}
origin: google/guava

private static boolean isThreadBlockedOn(Thread t, Object blocker) {
 return t.getState() == Thread.State.WAITING && LockSupport.getBlocker(t) == blocker;
}
origin: CarGuo/GSYVideoPlayer

private synchronized void readSourceAsync() throws ProxyCacheException {
  boolean readingInProgress = sourceReaderThread != null && sourceReaderThread.getState() != Thread.State.TERMINATED;
  if (!stopped && !cache.isCompleted() && !readingInProgress) {
    sourceReaderThread = new Thread(new SourceReaderRunnable(), "Source reader for " + source);
    sourceReaderThread.start();
  }
}
origin: neo4j/neo4j

@Override
public String toString()
{
  Thread thread = this.thread;
  return format( "%s[%s,state=%s]", getClass().getSimpleName(), name,
          thread == null ? "dead" : thread.getState() );
}
origin: google/guava

void joinSuccessfully(long timeoutMillis) {
 Uninterruptibles.joinUninterruptibly(thread, timeoutMillis, MILLISECONDS);
 completed.assertCompletionExpected();
 assertEquals(Thread.State.TERMINATED, thread.getState());
}
origin: google/guava

void joinSuccessfully() {
 Uninterruptibles.joinUninterruptibly(thread);
 completed.assertCompletionExpected();
 assertEquals(Thread.State.TERMINATED, thread.getState());
}
origin: neo4j/neo4j

@Override
public boolean test( Thread thread )
{
  ReflectionUtil.verifyMethodExists( owner, method );
  if ( thread.getState() == Thread.State.WAITING || thread.getState() == Thread.State.TIMED_WAITING )
  {
    for ( StackTraceElement element : thread.getStackTrace() )
    {
      if ( element.getClassName().equals( owner.getName() ) && element.getMethodName().equals( method ) )
      {
        return true;
      }
    }
  }
  return false;
}
origin: google/guava

/**
 * Waits for the specified time (in milliseconds) for the thread to terminate (using {@link
 * Thread#join(long)}), else interrupts the thread (in the hope that it may terminate later) and
 * fails.
 */
void awaitTermination(Thread t, long timeoutMillis) {
 try {
  t.join(timeoutMillis);
 } catch (InterruptedException ie) {
  threadUnexpectedException(ie);
 } finally {
  if (t.getState() != Thread.State.TERMINATED) {
   t.interrupt();
   fail("Test timed out");
  }
 }
}
origin: google/guava

/**
 * Spin-waits up to the specified number of milliseconds for the given thread to enter a wait
 * state: BLOCKED, WAITING, or TIMED_WAITING.
 */
void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
 long startTime = System.nanoTime();
 for (; ; ) {
  Thread.State s = thread.getState();
  if (s == Thread.State.BLOCKED || s == Thread.State.WAITING || s == Thread.State.TIMED_WAITING)
   return;
  else if (s == Thread.State.TERMINATED) fail("Unexpected thread termination");
  else if (millisElapsedSince(startTime) > timeoutMillis) {
   threadAssertTrue(thread.isAlive());
   return;
  }
  Thread.yield();
 }
}
origin: google/guava

 void joinUnsuccessfully(long timeoutMillis) {
  Uninterruptibles.joinUninterruptibly(thread, timeoutMillis, MILLISECONDS);
  completed.assertCompletionNotExpected(timeoutMillis);
  assertFalse(Thread.State.TERMINATED.equals(thread.getState()));
 }
}
origin: eclipse-vertx/vert.x

@Test
public void testCloseWorkerPool() throws Exception {
 String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
 AtomicReference<Thread> thread = new AtomicReference<>();
 WorkerExecutor worker1 = vertx.createSharedWorkerExecutor(poolName);
 WorkerExecutor worker2 = vertx.createSharedWorkerExecutor(poolName);
 worker1.executeBlocking(fut -> {
  thread.set(Thread.currentThread());
 }, ar -> {
 });
 assertWaitUntil(() -> thread.get() != null);
 worker1.close();
 assertNotSame(thread.get().getState(), Thread.State.TERMINATED);
 worker2.close();
 assertWaitUntil(() -> thread.get().getState() == Thread.State.TERMINATED);
}
origin: google/guava

public void testThreadFactory() throws InterruptedException {
 final String THREAD_NAME = "ludicrous speed";
 final int THREAD_PRIORITY = 1;
 final boolean THREAD_DAEMON = false;
 ThreadFactory backingThreadFactory =
   new ThreadFactory() {
    @Override
    public Thread newThread(Runnable r) {
     Thread thread = new Thread(r);
     thread.setName(THREAD_NAME);
     thread.setPriority(THREAD_PRIORITY);
     thread.setDaemon(THREAD_DAEMON);
     thread.setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
     return thread;
    }
   };
 Thread thread =
   builder.setThreadFactory(backingThreadFactory).build().newThread(monitoredRunnable);
 assertEquals(THREAD_NAME, thread.getName());
 assertEquals(THREAD_PRIORITY, thread.getPriority());
 assertEquals(THREAD_DAEMON, thread.isDaemon());
 assertSame(UNCAUGHT_EXCEPTION_HANDLER, thread.getUncaughtExceptionHandler());
 assertSame(Thread.State.NEW, thread.getState());
 assertFalse(completed);
 thread.start();
 thread.join();
 assertTrue(completed);
}
java.langThreadgetState

Javadoc

Returns the state of this thread. This method is designed for use in monitoring of the system state, not for synchronization control.

Popular methods of Thread

  • currentThread
  • sleep
    Causes the currently executing thread to sleep (temporarily cease execution) for the specified numbe
  • <init>
    Constructs a new Thread with no Runnable object, the given name and belonging to the ThreadGroup pas
  • start
    Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread
  • getContextClassLoader
    Returns the context ClassLoader for this Thread. The context ClassLoader is provided by the creator
  • interrupt
    Interrupts this thread. Unless the current thread is interrupting itself, which is always permitted,
  • setDaemon
    Marks this thread as either a #isDaemon thread or a user thread. The Java Virtual Machine exits when
  • getName
    Returns this thread's name.
  • join
    Waits at most millis milliseconds plus nanos nanoseconds for this thread to die. This implementatio
  • setContextClassLoader
    Sets the context ClassLoader for this Thread. The context ClassLoader can be set when a thread is cr
  • setName
    Changes the name of this thread to be equal to the argumentname. First the checkAccess method of thi
  • interrupted
    Tests whether the current thread has been interrupted. Theinterrupted status of the thread is cleare
  • setName,
  • interrupted,
  • getStackTrace,
  • getId,
  • isInterrupted,
  • isAlive,
  • setPriority,
  • yield,
  • getThreadGroup,
  • getPriority

Popular in Java

  • Creating JSON documents from java classes using gson
  • setContentView (Activity)
  • putExtra (Intent)
  • getResourceAsStream (ClassLoader)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Table (org.hibernate.mapping)
    A relational table
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now