I'm facing an unusual behavior when trying to experiment with java 19 virtual thread, the code below works perfectly with platform thread. but it exits suddenly when i switch to virtual thread. adding while(true); at the end solves the problem and the program keeps printing "hello". is it possible to use virtual thread with ScheduledExecutorService?
ThreadFactory factory = Thread.ofVirtual().factory();
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(factory);
scheduledExecutorService.scheduleAtFixedRate(() -> {
System.out.println("hello");
}, 0, 5000, TimeUnit.MILLISECONDS);
}
//while(true);