import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.CountDownLatch;

public class PollerTest{
    public static void main(String[] args) throws Exception {
        String isLinux = System.getProperty("os.name").toLowerCase();
        if (!isLinux.contains("linux")) {
            System.setProperty("jdk.pollerMode", "2");
        }

        int parallelism = Runtime.getRuntime().availableProcessors();
        CountDownLatch latch = new CountDownLatch(parallelism);

        System.out.println("checkpoint");

        for (int i = 0; i < parallelism; i++) {
            Thread.startVirtualThread(() -> {
                try {
                    new Tcp();//call Socket.connect during class loading
                } finally {
                    latch.countDown();
                }
            });
        }
        Thread.sleep(10);

        latch.await();
        System.out.println("All tasks completed");
    }

    static class Tcp {
        static {
            try (Socket socket = new Socket()) {
                socket.connect(new InetSocketAddress("bugreport.java.com", 443));
                System.out.println("Connected to bugreport.java.com");
            } catch (Exception e) {

            }
        }
    }
} 