在 32 位机器中 Java 中可以创建的线程数

Number of threads that can be created in Java in 32 bits machines

我正在阅读 Java concurrency in Practice 并且在下面的段落中有点迷路,关于在 32 位机器中 Java 中可以创建的线程数:

On 32 bit machines, a major limiting factor is address space for thread stacks. Each thread maintains two execution stacks, one for Java code and one for native code. Typical JVM defaults yield a combined stack size of around half a megabyte. (You can change this with the -Xss JVM flag or through the Thread constructor.) If you divide the per thread stack size into 232, you get a limit of a few thousands or tens of thousands of threads. Other factors, such as OS limitations, may impose stricter limits.

这是什么意思? 232这个数字是从哪里来的呢?如果 Thread 类中没有将堆栈大小作为参数的构造函数,我如何更改 Thread 构造函数中的堆栈大小?

  1. 有一个constructor将堆栈大小作为参数。

  2. 2^32是虚拟地址的大小space.

图232是对32位进程address space大小的硬性限制。 “32位处理”是指每个地址用32位来表示,因此最多可以有232个不同的地址。

该段是说由于每个线程必须为线程堆栈保留大约 512 * 1024 个地址,因此由于地址数量有限,因此只能有这么多线程。

请注意,232 是理论上的定义极限。实际上,如果 OS 使 32 位进程可以使用其中的 3/4,您可能会认为自己很幸运。