News for hackers. Stuff that matters.
Re:Fast, Safe, and Complete(ish) Web Service in Rust by vbezhenar on Wednesday March 28, 2018 @04:13AM (#16696231)
I'm talking about real threads, not green threads and I used Java for my quick test. Here's code, you can run it yourself. masklinn is correct about virtual memory, every sane OS will only use few kilobytes for short stacks.

    public class Test {
        volatile static boolean stop = false;
        static AtomicInteger counter = new AtomicInteger();
        public static void main(String[] args) throws InterruptedException {
            Thread[] threads = new Thread[100000];
            for (int i = 0; i < threads.length; i++) {
                threads[i] = new Thread(() -> {
                    counter.incrementAndGet();
                    while (!stop) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException ignored) {
                        }
                    }
                });
            }
            for (Thread thread : threads) {
                thread.start();
            }
            while (counter.get() < threads.length) {
                Thread.sleep(1000);
            }
            System.out.println("Threads are running");
            Thread.sleep(10000);
            stop = true;
            for (Thread thread : threads) {
                thread.join();
            }
        }
    }

There are no comments on this comment yet.