< prev index next > test/jdk/java/lang/management/ThreadMXBean/VirtualThreads.java
Print this page
ThreadInfo[] infos = bean.dumpAllThreads(false, false, maxDepth);
Set<Long> tids = Arrays.stream(infos)
.map(ThreadInfo::getThreadId)
.collect(Collectors.toSet());
! // current thread should be included
! assertTrue(tids.contains(Thread.currentThread().threadId()));
// virtual thread should not be included
assertFalse(tids.contains(vthread.threadId()));
} finally {
LockSupport.unpark(vthread);
ThreadInfo[] infos = bean.dumpAllThreads(false, false, maxDepth);
Set<Long> tids = Arrays.stream(infos)
.map(ThreadInfo::getThreadId)
.collect(Collectors.toSet());
! // if current thread is a platform thread then it should be included
! boolean expected = !Thread.currentThread().isVirtual();
+ assertEquals(expected, tids.contains(Thread.currentThread().threadId()));
// virtual thread should not be included
assertFalse(tids.contains(vthread.threadId()));
} finally {
LockSupport.unpark(vthread);
void testGetAllThreadIds() {
Thread vthread = Thread.startVirtualThread(LockSupport::park);
try {
long[] tids = ManagementFactory.getThreadMXBean().getAllThreadIds();
! // current thread should be included
long currentTid = Thread.currentThread().threadId();
! assertTrue(Arrays.stream(tids).anyMatch(tid -> tid == currentTid));
// virtual thread should not be included
long vtid = vthread.threadId();
assertFalse(Arrays.stream(tids).anyMatch(tid -> tid == vtid));
} finally {
void testGetAllThreadIds() {
Thread vthread = Thread.startVirtualThread(LockSupport::park);
try {
long[] tids = ManagementFactory.getThreadMXBean().getAllThreadIds();
! // if current thread is a platform thread then it should be included
+ boolean expected = !Thread.currentThread().isVirtual();
long currentTid = Thread.currentThread().threadId();
! assertEquals(expected, Arrays.stream(tids).anyMatch(tid -> tid == currentTid));
// virtual thread should not be included
long vtid = vthread.threadId();
assertFalse(Arrays.stream(tids).anyMatch(tid -> tid == vtid));
} finally {
try {
long tid0 = Thread.currentThread().threadId();
long tid1 = vthread.threadId();
long[] tids = new long[] { tid0, tid1 };
ThreadInfo[] infos = ManagementFactory.getThreadMXBean().getThreadInfo(tids, maxDepth);
! assertEquals(tid0, infos[0].getThreadId());
assertNull(infos[1]);
} finally {
LockSupport.unpark(vthread);
}
}
try {
long tid0 = Thread.currentThread().threadId();
long tid1 = vthread.threadId();
long[] tids = new long[] { tid0, tid1 };
ThreadInfo[] infos = ManagementFactory.getThreadMXBean().getThreadInfo(tids, maxDepth);
! if (Thread.currentThread().isVirtual()) {
+ assertNull(infos[0]);
+ } else {
+ assertEquals(tid0, infos[0].getThreadId());
+ }
assertNull(infos[1]);
} finally {
LockSupport.unpark(vthread);
}
}
long tid0 = Thread.currentThread().threadId();
long tid1 = vthread.threadId();
long[] tids = new long[] { tid0, tid1 };
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] infos = bean.getThreadInfo(tids, false, false, maxDepth);
! assertEquals(tid0, infos[0].getThreadId());
assertNull(infos[1]);
} finally {
LockSupport.unpark(vthread);
}
}
long tid0 = Thread.currentThread().threadId();
long tid1 = vthread.threadId();
long[] tids = new long[] { tid0, tid1 };
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] infos = bean.getThreadInfo(tids, false, false, maxDepth);
! if (Thread.currentThread().isVirtual()) {
+ assertNull(infos[0]);
+ } else {
+ assertEquals(tid0, infos[0].getThreadId());
+ }
assertNull(infos[1]);
} finally {
LockSupport.unpark(vthread);
}
}
< prev index next >