@Override public long id() { return t.getId(); }
@Override public boolean test(final Thread thread) { return thread != null && thread.getId() == threadId; } }
Thread t = Thread.currentThread(); int id = t.getId();
private class MyTask implements Runnable { public void run() { long threadId = Thread.currentThread().getId(); logger.debug("Thread # " + threadId + " is doing this task"); } }
@Override public void uncaughtException(Thread t, Throwable ex) { // if this was an OutOfMemoryError then all bets about logging are off - but in the absence of anything else... LOGGER.log(Level.SEVERE, "A thread (" + t.getName() + '/' + t.getId() + ") died unexpectedly due to an uncaught exception, this may leave your Jenkins in a bad way and is usually indicative of a bug in the code.", ex); }
public void removeFromWaitingThreadTable() { long currentThreadId = Thread.currentThread().getId(); synchronized (this) { this.waitingThreadTable.remove(currentThreadId); } } }
/** * Acquire the light lock protecting this consumer from multi-threaded access. Instead of blocking * when the lock is not available, however, we just throw an exception (since multi-threaded usage is not * supported). * @throws ConcurrentModificationException if another thread already has the lock */ private void acquire() { long threadId = Thread.currentThread().getId(); if (threadId != currentThread.get() && !currentThread.compareAndSet(NO_CURRENT_THREAD, threadId)) throw new ConcurrentModificationException("KafkaConsumer is not safe for multi-threaded access"); refcount.incrementAndGet(); }
private ThreadSorterBase() { ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent() != null) tg = tg.getParent(); Thread[] threads = new Thread[tg.activeCount()*2]; int threadsLen = tg.enumerate(threads, true); for (int i = 0; i < threadsLen; i++) { ThreadGroup group = threads[i].getThreadGroup(); map.put(threads[i].getId(), group != null ? group.getName() : null); } }
@Override public RFuture<Void> unlockAsync() { long threadId = Thread.currentThread().getId(); return unlockAsync(threadId); }
@Override public RFuture<Void> lockAsync(long leaseTime, TimeUnit unit) { final long currentThreadId = Thread.currentThread().getId(); return lockAsync(leaseTime, unit, currentThreadId); }
@Override public RFuture<Void> unlockAsync() { long threadId = Thread.currentThread().getId(); return unlockAsync(threadId); }
@Override public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit) { long currentThreadId = Thread.currentThread().getId(); return tryLockAsync(waitTime, leaseTime, unit, currentThreadId); }
@Override public RFuture<Void> lockAsync(long leaseTime, TimeUnit unit) { final long currentThreadId = Thread.currentThread().getId(); return lockAsync(leaseTime, unit, currentThreadId); }
@Override public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit) { long currentThreadId = Thread.currentThread().getId(); return tryLockAsync(waitTime, leaseTime, unit, currentThreadId); }
@Override public boolean isHeldByCurrentThread() { return isHeldByThread(Thread.currentThread().getId()); }
@Override public void run() { if (running != null) { running.countDown(); } for (int i = 0; i < numStringsToSend; i++) { observer.onNext(Thread.currentThread().getId() + "-" + i); if (latch != null) { latch.countDown(); } produced.incrementAndGet(); } } }
@Override public void run() { if (running != null) { running.countDown(); } for (int i = 0; i < numStringsToSend; i++) { subscriber.onNext(Thread.currentThread().getId() + "-" + i); if (latch != null) { latch.countDown(); } produced.incrementAndGet(); } } }
@Test(expected=IllegalArgumentException.class) public void testThreadGroupsByIdFail() throws InterruptedException { ThreadUtils.findThreadById(Thread.currentThread().getId(), (String) null); }
@Test public void testThreadsByIdWrongGroup() throws InterruptedException { final Thread t1 = new TestThread("thread1_XXOOLL__"); final ThreadGroup tg = new ThreadGroup("tg__HHEE22"); try { t1.start(); assertNull(ThreadUtils.findThreadById(t1.getId(), tg)); } finally { t1.interrupt(); t1.join(); tg.destroy(); } }