< prev index next > test/jdk/java/lang/Thread/virtual/ThreadAPI.java
Print this page
@MethodSource("oneSecondSleepers")
void testSleep3(ThrowingRunnable sleeper) throws Exception {
VThreadRunner.run(() -> {
long start = millisTime();
sleeper.run();
! expectDuration(start, /*min*/900, /*max*/4000);
});
}
/**
* Tasks that sleep for zero or longer duration.
@MethodSource("oneSecondSleepers")
void testSleep3(ThrowingRunnable sleeper) throws Exception {
VThreadRunner.run(() -> {
long start = millisTime();
sleeper.run();
! expectDuration(start, /*min*/900, /*max*/20_000);
});
}
/**
* Tasks that sleep for zero or longer duration.
VThreadRunner.run(() -> {
LockSupport.unpark(Thread.currentThread());
long start = millisTime();
Thread.sleep(1000);
! expectDuration(start, /*min*/900, /*max*/4000);
// check that parking permit was not consumed
LockSupport.park();
});
}
VThreadRunner.run(() -> {
LockSupport.unpark(Thread.currentThread());
long start = millisTime();
Thread.sleep(1000);
! expectDuration(start, /*min*/900, /*max*/20_000);
// check that parking permit was not consumed
LockSupport.park();
});
}
AtomicReference<Exception> exc = new AtomicReference<>();
var thread = Thread.ofVirtual().start(() -> {
try {
long start = millisTime();
Thread.sleep(1000);
! expectDuration(start, /*min*/900, /*max*/4000);
} catch (Exception e) {
exc.set(e);
}
});
AtomicReference<Exception> exc = new AtomicReference<>();
var thread = Thread.ofVirtual().start(() -> {
try {
long start = millisTime();
Thread.sleep(1000);
! expectDuration(start, /*min*/900, /*max*/20_000);
} catch (Exception e) {
exc.set(e);
}
});
VThreadRunner.run(() -> {
long start = millisTime();
synchronized (lock) {
Thread.sleep(1000);
}
! expectDuration(start, /*min*/900, /*max*/4000);
});
}
/**
* Test Thread.sleep when pinned and with interrupt status set.
VThreadRunner.run(() -> {
long start = millisTime();
synchronized (lock) {
Thread.sleep(1000);
}
! expectDuration(start, /*min*/900, /*max*/20_000);
});
}
/**
* Test Thread.sleep when pinned and with interrupt status set.
} finally {
t.setContextClassLoader(savedLoader);
}
}
- /**
- * Test Thread.xxxContextClassLoader when thread locals not supported.
- */
- @Test
- void testContextClassLoader5() throws Exception {
- ClassLoader scl = ClassLoader.getSystemClassLoader();
- ClassLoader loader = new ClassLoader() { };
- VThreadRunner.run(VThreadRunner.NO_THREAD_LOCALS, () -> {
- Thread t = Thread.currentThread();
- assertTrue(t.getContextClassLoader() == scl);
- assertThrows(UnsupportedOperationException.class,
- () -> t.setContextClassLoader(loader));
- assertTrue(t.getContextClassLoader() == scl);
- });
- }
-
/**
* Test Thread.xxxContextClassLoader when thread does not inherit the
* initial value of inheritable thread locals.
*/
@Test
! void testContextClassLoader6() throws Exception {
VThreadRunner.run(() -> {
ClassLoader loader = new ClassLoader() { };
Thread.currentThread().setContextClassLoader(loader);
int characteristics = VThreadRunner.NO_INHERIT_THREAD_LOCALS;
VThreadRunner.run(characteristics, () -> {
} finally {
t.setContextClassLoader(savedLoader);
}
}
/**
* Test Thread.xxxContextClassLoader when thread does not inherit the
* initial value of inheritable thread locals.
*/
@Test
! void testContextClassLoader5() throws Exception {
VThreadRunner.run(() -> {
ClassLoader loader = new ClassLoader() { };
Thread.currentThread().setContextClassLoader(loader);
int characteristics = VThreadRunner.NO_INHERIT_THREAD_LOCALS;
VThreadRunner.run(characteristics, () -> {
< prev index next >