Java 1.7中可以管理多少个线程?

时间:2021-11-29 21:02:29

How many threads about Java 1.7 are capable of managing? In Server/Client Web Program wich clients can login To Server. This Login is statefull. Clients > 3000 per Server

有关Java 1.7的多少线程能够管理?在服务器/客户端Web程序中,客户端可以登录到服务器。此登录状态为statefull。客户端>每服务器3000个

6 个解决方案

#1


1  

Java has APIs which limit the number of Threads to Integer.MAX_VALUE. (~ 2 billion)

Java具有将线程数限制为Integer.MAX_VALUE的API。 (约20亿)

However your OS/Hardware will be the real restriction. Between 100 and 10K will be your limit depending on what you are doing.

但是,您的操作系统/硬件将是真正的限制。根据您的工作情况,100到10K将是您的限制。

Threads are usually created to improve performance. However they add overhead so you will reach a point where adding threads will decrease performance. In rare cases two threads are not as good as one. The point at which more threads hurts performance depends on your application, your hardware and how it is used.

通常创建线程以提高性能。但是,它们会增加开销,因此您将达到添加线程会降低性能的程度。在极少数情况下,两个线程不如一个线程。更多线程损害性能的程度取决于您的应用程序,硬件及其使用方式。

Note: If you have 16 logical cores, there will only be up to 16 threads running at any given moment.

注意:如果您有16个逻辑核心,则在任何给定时刻最多只能运行16个线程。

#2


3  

"Enough". If not, you use thread pools with an appropriate Executor. What is it you need to do?

“足够”。如果没有,则使用具有适当Executor的线程池。你需要做什么?

#3


1  

There isn't a Java 1.7 (yet). On a 64-bit system you can go to tens of thousands. On 32-bit systems you are largely limited to virtual address spaces for stacks.

还没有Java 1.7(还)。在64位系统上,您可以达到数万个。在32位系统上,您主要限于堆栈的虚拟地址空间。

Long page on the "c10k" problem.

关于“c10k”问题的长篇大论。

#4


1  

In theory? Thousands.

理论上?数千人。

In practice - depends entirely on your system. You're more likely to run out of memory before you run out of threads.

在实践中 - 完全取决于您的系统。在用完线程之前,你更有可能耗尽内存。

#5


-1  

I would imagine the upper bound has some relation to the available heap space. But the realistic limit has more to do with the hardware you are running the system on than the version of Java.

我认为上限与可用堆空间有一些关系。但实际限制更多地与运行系统的硬件有关,而不是Java版本。

#6


-1  

Each thread has its own stack space. The stack is stored outside of the heap but within the JVM's allocated memory. Thus the maximum threads is typically bound by how much memory the OS can allocated to the JVM. On Windows this corresponds to about 1000-2000 maximum threads before the JVM is out of memory.

每个线程都有自己的堆栈空间。堆栈存储在堆外部,但存储在JVM的已分配内存中。因此,最大线程通常受操作系统可以分配给JVM的内存量的限制。在Windows上,这相当于在JVM内存不足之前大约1000-2000个最大线程。

#1


1  

Java has APIs which limit the number of Threads to Integer.MAX_VALUE. (~ 2 billion)

Java具有将线程数限制为Integer.MAX_VALUE的API。 (约20亿)

However your OS/Hardware will be the real restriction. Between 100 and 10K will be your limit depending on what you are doing.

但是,您的操作系统/硬件将是真正的限制。根据您的工作情况,100到10K将是您的限制。

Threads are usually created to improve performance. However they add overhead so you will reach a point where adding threads will decrease performance. In rare cases two threads are not as good as one. The point at which more threads hurts performance depends on your application, your hardware and how it is used.

通常创建线程以提高性能。但是,它们会增加开销,因此您将达到添加线程会降低性能的程度。在极少数情况下,两个线程不如一个线程。更多线程损害性能的程度取决于您的应用程序,硬件及其使用方式。

Note: If you have 16 logical cores, there will only be up to 16 threads running at any given moment.

注意:如果您有16个逻辑核心,则在任何给定时刻最多只能运行16个线程。

#2


3  

"Enough". If not, you use thread pools with an appropriate Executor. What is it you need to do?

“足够”。如果没有,则使用具有适当Executor的线程池。你需要做什么?

#3


1  

There isn't a Java 1.7 (yet). On a 64-bit system you can go to tens of thousands. On 32-bit systems you are largely limited to virtual address spaces for stacks.

还没有Java 1.7(还)。在64位系统上,您可以达到数万个。在32位系统上,您主要限于堆栈的虚拟地址空间。

Long page on the "c10k" problem.

关于“c10k”问题的长篇大论。

#4


1  

In theory? Thousands.

理论上?数千人。

In practice - depends entirely on your system. You're more likely to run out of memory before you run out of threads.

在实践中 - 完全取决于您的系统。在用完线程之前,你更有可能耗尽内存。

#5


-1  

I would imagine the upper bound has some relation to the available heap space. But the realistic limit has more to do with the hardware you are running the system on than the version of Java.

我认为上限与可用堆空间有一些关系。但实际限制更多地与运行系统的硬件有关,而不是Java版本。

#6


-1  

Each thread has its own stack space. The stack is stored outside of the heap but within the JVM's allocated memory. Thus the maximum threads is typically bound by how much memory the OS can allocated to the JVM. On Windows this corresponds to about 1000-2000 maximum threads before the JVM is out of memory.

每个线程都有自己的堆栈空间。堆栈存储在堆外部,但存储在JVM的已分配内存中。因此,最大线程通常受操作系统可以分配给JVM的内存量的限制。在Windows上,这相当于在JVM内存不足之前大约1000-2000个最大线程。