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

How to use
currentThread
method
in
java.lang.Thread

Best Java code snippets using java.lang.Thread.currentThread (Showing top 20 results out of 117,693)

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: 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: iluwatar/java-design-patterns

 @Override
 public void run() {
  LOGGER.info("{} processing {}", Thread.currentThread().getName(), task.toString());
  try {
   Thread.sleep(task.getTimeMs());
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 }
}
origin: ReactiveX/RxJava

static void uncaught(@NonNull Throwable error) {
  Thread currentThread = Thread.currentThread();
  UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler();
  handler.uncaughtException(currentThread, error);
}
origin: ReactiveX/RxJava

  @Override
  public String apply(String v) {
    System.out.println("ObserveOn Thread: " + Thread.currentThread());
    return v;
  }
})
origin: ReactiveX/RxJava

@Override
public void run() {
  t = Thread.currentThread();
  latch.countDown();
}
origin: ReactiveX/RxJava

  @Override
  public void accept(Throwable throwable) throws Exception {
    thread.set(Thread.currentThread());
    latch.countDown();
  }
})
origin: ReactiveX/RxJava

  @Override
  public void run() throws Exception {
    name[0] = Thread.currentThread().getName();
    cdl.countDown();
  }
})
origin: ReactiveX/RxJava

  @Override
  public void accept(Throwable throwable) throws Exception {
    thread.set(Thread.currentThread());
    latch.countDown();
  }
})
origin: ReactiveX/RxJava

  @Override
  public Object apply(Integer v) throws Exception {
    return Thread.currentThread().getName().substring(0, 4);
  }
}),
origin: ReactiveX/RxJava

  @Override
  public void accept(Object v) throws Exception {
    interrupted.set(Thread.currentThread().isInterrupted());
    cdl.countDown();
  }
});
origin: ReactiveX/RxJava

  @Override
  public void run() throws Exception {
    interrupted.set(Thread.currentThread().isInterrupted());
    cdl.countDown();
  }
});
origin: ReactiveX/RxJava

  @Override
  public void onNext(Integer t) {
    System.err.println("testSubscriber received => " + t + "  on thread " + Thread.currentThread());
    super.onNext(t);
  }
};
origin: ReactiveX/RxJava

  @Override
  public void subscribe(Subscriber<? super Integer> t1) {
    subscribeThread.set(Thread.currentThread());
    t1.onSubscribe(subscription);
    t1.onNext(1);
    t1.onNext(2);
    // observeOn will prevent canceling the upstream upon its termination now
    // this call is racing for that state in this test
    // not doing it will make sure the unsubscribeOn always gets through
    // t1.onComplete();
  }
});
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: 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 = 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 subscribe(Observer<? super Integer> t1) {
    subscribeThread.set(Thread.currentThread());
    t1.onSubscribe(subscription);
    t1.onNext(1);
    t1.onNext(2);
    // observeOn will prevent canceling the upstream upon its termination now
    // this call is racing for that state in this test
    // not doing it will make sure the unsubscribeOn always gets through
    // t1.onComplete();
  }
});
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

@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.langThreadcurrentThread

Javadoc

Returns a reference to the currently executing thread object.

Popular methods of Thread

  • 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
  • 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

  • Running tasks concurrently on multiple threads
  • onRequestPermissionsResult (Fragment)
  • setContentView (Activity)
  • putExtra (Intent)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • CodeWhisperer alternatives
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