Код: Выделить всё
import java.math.BigInteger;
import java.time.LocalDateTime;
public class VirtualThreadTest {
public static void main(String[] args) {
for(int i = 1; i {
System.out.println(LocalDateTime.now());
System.out.flush();
expensiveTask();
});
}
sleepMainThread();
}
private static void expensiveTask() {
var bi = BigInteger.ONE;
for(int i = 2; i < 50_000; i+=1) {
bi = bi.multiply(BigInteger.valueOf(i));
}
}
private static void sleepMainThread() {
try {
Thread.sleep(60_000);
} catch(Exception e) { e.printStackTrace(); }
}
}
Код: Выделить всё
2024-05-08T14:17:34.925188363
2024-05-08T14:17:34.925920200
2024-05-08T14:17:34.925993640
2024-05-08T14:17:34.926365126
...
2024-05-08T14:17:50.927143298
2024-05-08T14:17:51.136285346
2024-05-08T14:17:34.925684196 // prints value in the past
2024-05-08T14:17:51.251390867
2024-05-08T14:17:51.309471812
Подробнее здесь: https://stackoverflow.com/questions/784 ... al-threads