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

How to use
isAlive
method
in
java.lang.Thread

Best Java code snippets using java.lang.Thread.isAlive (Showing top 20 results out of 10,233)

origin: netty/netty

  @Override
  public boolean isAlive() {
    return t.isAlive();
  }
}
origin: androidannotations/androidannotations

/**
 * Indicates whether the server is currently running.
 * 
 * @return True if the server is running, false otherwise.
 * 
 * @see #start()
 * @see #stop() see WindowManagerService#isViewServerRunning()
 */
public boolean isRunning() {
  return mThread != null && mThread.isAlive();
}
origin: airbnb/lottie-android

 private boolean taskObserverAlive() {
  return taskObserver != null && taskObserver.isAlive();
 }
}
origin: redisson/redisson

  @Override
  public boolean isAlive() {
    return t.isAlive();
  }
}
origin: apache/kafka

private void throwIfProducerClosed() {
  if (ioThread == null || !ioThread.isAlive())
    throw new IllegalStateException("Cannot perform operation after producer has been closed");
}
origin: ctripcorp/apollo

 @Override
 public boolean satisfy(Thread thread) {
  return !thread.isAlive() || thread.isInterrupted() || thread.isDaemon();
 }
});
origin: apache/kafka

@Override
public void close() {
  if ((t != null) && (t.isAlive())) {
    t.interrupt();
    try {
      t.join();
    } catch (InterruptedException e) {
      log.warn("[Principal={}]: Error while waiting for Login thread to shutdown.", principal, e);
      Thread.currentThread().interrupt();
    }
  }
}
origin: netty/netty

/**
 * Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself.
 * Because a new worker thread will be started again when a new task is submitted, this operation is only useful
 * when you want to ensure that the worker thread is terminated <strong>after</strong> your application is shut
 * down and there's no chance of submitting a new task afterwards.
 *
 * @return {@code true} if and only if the worker thread has been terminated
 */
public boolean awaitInactivity(long timeout, TimeUnit unit) throws InterruptedException {
  if (unit == null) {
    throw new NullPointerException("unit");
  }
  final Thread thread = this.thread;
  if (thread == null) {
    throw new IllegalStateException("thread was not started");
  }
  thread.join(unit.toMillis(timeout));
  return !thread.isAlive();
}
origin: apache/kafka

public void close() {
  if (refresherThread != null && refresherThread.isAlive()) {
    refresherThread.interrupt();
    try {
      refresherThread.join();
    } catch (InterruptedException e) {
      log.warn("[Principal={}]: Interrupted while waiting for re-login thread to shutdown.",
          principalLogText(), e);
      Thread.currentThread().interrupt();
    }
  }
}
origin: netty/netty

  private void notifyWatchees() {
    List<Entry> watchees = this.watchees;
    for (int i = 0; i < watchees.size();) {
      Entry e = watchees.get(i);
      if (!e.thread.isAlive()) {
        watchees.remove(i);
        try {
          e.task.run();
        } catch (Throwable t) {
          logger.warn("Thread death watcher task raised an exception:", t);
        }
      } else {
        i ++;
      }
    }
  }
}
origin: google/guava

 @Override
 public void tearDown() throws Exception {
  interruptingTask.stopInterrupting();
  interruptingThread.interrupt();
  joinUninterruptibly(interruptingThread, 2500, MILLISECONDS);
  Thread.interrupted();
  if (interruptingThread.isAlive()) {
   // This will be hidden by test-output redirection:
   logger.severe("InterruptenatorTask did not exit; future tests may be affected");
   /*
    * This won't do any good under JUnit 3, but I'll leave it around in
    * case we ever switch to JUnit 4:
    */
   fail();
  }
 }
});
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

/** Checks that thread does not terminate within the given millisecond delay. */
void assertThreadStaysAlive(Thread thread, long millis) {
 try {
  // No need to optimize the failing case via Thread.join.
  delay(millis);
  assertTrue(thread.isAlive());
 } catch (InterruptedException ie) {
  fail("Unexpected InterruptedException");
 }
}
origin: google/guava

/** Checks that the threads do not terminate within the given millisecond delay. */
void assertThreadsStayAlive(long millis, Thread... threads) {
 try {
  // No need to optimize the failing case via Thread.join.
  delay(millis);
  for (Thread thread : threads) assertTrue(thread.isAlive());
 } catch (InterruptedException ie) {
  fail("Unexpected InterruptedException");
 }
}
origin: google/guava

public void testJoinWithNoWait() throws InterruptedException {
 Stopwatch stopwatch = Stopwatch.createStarted();
 Thread thread = new Thread(new JoinTarget(15));
 thread.start();
 thread.join();
 assertFalse(thread.isAlive());
 joinUninterruptibly(thread);
 joinUninterruptibly(thread, 0, MILLISECONDS);
 joinUninterruptibly(thread, -42, MILLISECONDS);
 joinUninterruptibly(thread, LONG_DELAY_MS, MILLISECONDS);
 assertTimeNotPassed(stopwatch, LONG_DELAY_MS);
}
origin: google/guava

public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
 final NoOpThreadedService service = new NoOpThreadedService();
 service.addListener(
   new Listener() {
    @Override
    public void terminated(State from) {
     service.stopAsync().awaitTerminated();
    }
   },
   directExecutor());
 service.startAsync().awaitRunning();
 Thread thread =
   new Thread() {
    @Override
    public void run() {
     service.stopAsync().awaitTerminated();
    }
   };
 thread.start();
 thread.join(LONG_TIMEOUT_MILLIS);
 assertFalse(thread + " is deadlocked", thread.isAlive());
}
origin: google/guava

/**
 * Test for a bug where threads weren't getting signaled when shutdown was called, only when tasks
 * completed.
 */
public void testDirectExecutorService_awaitTermination_missedSignal() {
 final ExecutorService service = MoreExecutors.newDirectExecutorService();
 Thread waiter =
   new Thread() {
    @Override
    public void run() {
     try {
      service.awaitTermination(1, TimeUnit.DAYS);
     } catch (InterruptedException e) {
      return;
     }
    }
   };
 waiter.start();
 awaitTimedWaiting(waiter);
 service.shutdown();
 Uninterruptibles.joinUninterruptibly(waiter, 10, TimeUnit.SECONDS);
 if (waiter.isAlive()) {
  waiter.interrupt();
  fail("awaitTermination failed to trigger after shutdown()");
 }
}
origin: google/guava

public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
 final StartFailingService service = new StartFailingService();
 service.startAsync();
 assertEquals(State.FAILED, service.state());
 service.addListener(new RecordingListener(service), directExecutor());
 Thread thread =
   new Thread() {
    @Override
    public void run() {
     // Internally stopAsync() grabs a lock, this could be any such method on
     // AbstractService.
     service.stopAsync();
    }
   };
 thread.start();
 thread.join(LONG_TIMEOUT_MILLIS);
 assertFalse(thread + " is deadlocked", thread.isAlive());
}
origin: google/guava

public void testAwaitTerminated() throws Exception {
 final NoOpService service = new NoOpService();
 Thread waiter =
   new Thread() {
    @Override
    public void run() {
     service.awaitTerminated();
    }
   };
 waiter.start();
 service.startAsync().awaitRunning();
 assertEquals(State.RUNNING, service.state());
 service.stopAsync();
 waiter.join(LONG_TIMEOUT_MILLIS); // ensure that the await in the other thread is triggered
 assertFalse(waiter.isAlive());
}
origin: google/guava

public void testAwaitTerminated_FailedService() throws Exception {
 final ManualSwitchedService service = new ManualSwitchedService();
 final AtomicReference<Throwable> exception = Atomics.newReference();
 Thread waiter =
   new Thread() {
    @Override
    public void run() {
     try {
      service.awaitTerminated();
      fail("Expected an IllegalStateException");
     } catch (Throwable t) {
      exception.set(t);
     }
    }
   };
 waiter.start();
 service.startAsync();
 service.notifyStarted();
 assertEquals(State.RUNNING, service.state());
 service.notifyFailed(EXCEPTION);
 assertEquals(State.FAILED, service.state());
 waiter.join(LONG_TIMEOUT_MILLIS);
 assertFalse(waiter.isAlive());
 assertThat(exception.get()).isInstanceOf(IllegalStateException.class);
 assertThat(exception.get()).hasCauseThat().isEqualTo(EXCEPTION);
}
java.langThreadisAlive

Javadoc

Tests if this thread is alive. A thread is alive if it has been started and has not yet died.

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,
  • setPriority,
  • yield,
  • getThreadGroup,
  • getPriority

Popular in Java

  • Reactive rest calls using spring rest template
  • setScale (BigDecimal)
  • requestLocationUpdates (LocationManager)
  • getSystemService (Context)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • JComboBox (javax.swing)
  • Runner (org.openjdk.jmh.runner)
  • Best plugins for Eclipse
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