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

How to use
interrupt
method
in
java.lang.Thread

Best Java code snippets using java.lang.Thread.interrupt (Showing top 20 results out of 47,664)

origin: iluwatar/java-design-patterns

@Override
public void run() {
 writeLock.lock();
 try {
  write();
 } catch (InterruptedException e) {
  LOGGER.info("InterruptedException when writing", e);
  Thread.currentThread().interrupt();
 } finally {
  writeLock.unlock();
 }
}

origin: ReactiveX/RxJava

@Test
public void interrupted() {
  Iterator<Object> it = Observable.never().blockingLatest().iterator();
  Thread.currentThread().interrupt();
  try {
    it.hasNext();
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
  Thread.interrupted();
}
origin: iluwatar/java-design-patterns

@Override
public void run() {
 readLock.lock();
 try {
  read();
 } catch (InterruptedException e) {
  LOGGER.info("InterruptedException when reading", e);
  Thread.currentThread().interrupt();
 } finally {
  readLock.unlock();
 }
}
origin: ReactiveX/RxJava

@Test
public void awaitTerminalEventInterrupt() {
  final TestSubscriber<Integer> ts = TestSubscriber.create();
  ts.onSubscribe(new BooleanSubscription());
  Thread.currentThread().interrupt();
  ts.awaitTerminalEvent();
  assertTrue(Thread.interrupted());
  Thread.currentThread().interrupt();
  ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
  assertTrue(Thread.interrupted());
}
origin: ReactiveX/RxJava

  @Override
  public void run() {
    t0.interrupt();
  }
}, 200, TimeUnit.MILLISECONDS);
origin: ReactiveX/RxJava

@Test
public void interrupt() {
  TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L);
  Thread.currentThread().interrupt();
  try {
    Flowable.just(1)
    .blockingSubscribe(ts);
    ts.assertFailure(InterruptedException.class);
  } finally {
    Thread.interrupted(); // clear interrupted status just in case
  }
}
origin: ReactiveX/RxJava

  @Override
  public void run() {
    t0.interrupt();
  }
}, 200, TimeUnit.MILLISECONDS);
origin: ReactiveX/RxJava

  @Override
  public void run() {
    t0.interrupt();
  }
}, 200, TimeUnit.MILLISECONDS);
origin: ReactiveX/RxJava

@Test(expected = InterruptedException.class)
public void getInterrupted() throws Exception {
  Thread.currentThread().interrupt();
  fo.get();
}
origin: ReactiveX/RxJava

@Test
public void interruptTestWaitStrategy() {
  try {
    Thread.currentThread().interrupt();
    TestWaitStrategy.SLEEP_1000MS.run();
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

@Test
public void interrupt() {
  Iterator<Object> it = Flowable.never().blockingNext().iterator();
  try {
    Thread.currentThread().interrupt();
    it.next();
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

@Test
public void interrupt() {
  Iterator<Object> it = Observable.never().blockingNext().iterator();
  try {
    Thread.currentThread().interrupt();
    it.next();
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

  @Override
  public void accept(Emitter<Event> s) {
    s.onNext(randomEvent(type, numInstances));
    try {
      // slow it down somewhat
      Thread.sleep(50);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      s.onError(e);
    }
  }
}
origin: ReactiveX/RxJava

  @Override
  public void accept(Emitter<Event> s) {
    s.onNext(randomEvent(type, numInstances));
    try {
      // slow it down somewhat
      Thread.sleep(50);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      s.onError(e);
    }
  }
}
origin: ReactiveX/RxJava

@Test
public void interruptWait() {
  BlockingObservableIterator<Integer> it = new BlockingObservableIterator<Integer>(128);
  try {
    Thread.currentThread().interrupt();
    it.hasNext();
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

@Test
public void awaitDoneTimed() {
  TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  Thread.currentThread().interrupt();
  try {
    ts.awaitDone(5, TimeUnit.SECONDS);
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

@Test
public void awaitDoneTimed() {
  TestObserver<Integer> to = new TestObserver<Integer>();
  Thread.currentThread().interrupt();
  try {
    to.awaitDone(5, TimeUnit.SECONDS);
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

@Test(timeout = 5000)
public void blockingFirstTimeout() {
  BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>();
  Thread.currentThread().interrupt();
  try {
    bf.blockingGet();
    fail("Should have thrown!");
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
origin: ReactiveX/RxJava

@Test
public void interrupt() {
  TestObserver<Object> to = new TestObserver<Object>();
  Thread.currentThread().interrupt();
  Observable.never().blockingSubscribe(to);
}
origin: ReactiveX/RxJava

@Test(timeout = 5000)
public void blockingFirstTimeout2() {
  BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>();
  bf.onSubscribe(new BooleanSubscription());
  Thread.currentThread().interrupt();
  try {
    bf.blockingGet();
    fail("Should have thrown!");
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}
java.langThreadinterrupt

Javadoc

Interrupts this thread.

Unless the current thread is interrupting itself, which is always permitted, the #checkAccess() method of this thread is invoked, which may cause a SecurityException to be thrown.

If this thread is blocked in an invocation of the Object#wait(), Object#wait(long), or Object#wait(long,int) methods of the Objectclass, or of the #join(), #join(long), #join(long,int), #sleep(long), or #sleep(long,int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

If this thread is blocked in an I/O operation upon an java.nio.channels.InterruptibleChannel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a java.nio.channels.ClosedByInterruptException.

If this thread is blocked in a java.nio.channels.Selectorthen the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's java.nio.channels.Selector#wakeup method were invoked.

If none of the previous conditions hold then this thread's interrupt status will be set.

Interrupting a thread that is not alive need not have any effect.

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
  • 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
  • getStackTrace
    Returns an array of stack trace elements representing the stack dump of this thread. This method wil
  • interrupted,
  • getStackTrace,
  • getId,
  • isInterrupted,
  • isAlive,
  • setPriority,
  • yield,
  • getThreadGroup,
  • getPriority

Popular in Java

  • Making http post requests using okhttp
  • requestLocationUpdates (LocationManager)
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JPanel (javax.swing)
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Best IntelliJ 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