Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Um, lots.</p> <p>There are several parameters here. The specific VM, plus there are usually run-time parameters on the VM as well. That's somewhat driven by the operating system: what support does the underlying OS have for threads and what limitations does it put on them? If the VM actually uses OS-level threads at all, the good old red thread/green thread thing.</p> <p>What "support" means is another question. If you write a Java program that is just something like</p> <pre><code> class DieLikeADog { public static void main(String[] argv){ for(;;){ new Thread(new SomeRunaable).start(); } } } </code></pre> <p>(and don't complain about little syntax details, I'm on my first cup of coffee) then you should certainly expect to get hundreds or thousands of threads running. But <em>creating</em> a Thread is relatively expensive, and scheduler overhead can get intense; it's unclear that you could have those threads do anything useful.</p> <h3>Update</h3> <p>Okay, couldn't resist. Here's my little test program, with a couple embellishments:</p> <pre><code>public class DieLikeADog { private static Object s = new Object(); private static int count = 0; public static void main(String[] argv){ for(;;){ new Thread(new Runnable(){ public void run(){ synchronized(s){ count += 1; System.err.println("New thread #"+count); } for(;;){ try { Thread.sleep(1000); } catch (Exception e){ System.err.println(e); } } } }).start(); } } } </code></pre> <p>On OS/X 10.5.6 on Intel, and Java <s>6</s> 5 (see comments), here's what I got</p> <pre> New thread #2547 New thread #2548 New thread #2549 Can't create thread: 5 New thread #2550 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:592) at DieLikeADog.main(DieLikeADog.java:6) </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload