想测试一下平台支持的最大的线程数,想知道有没有这样的示例程序。
谢谢!
谢谢!
解决方案 »
- jdbc
- drawImage 时候 java.lang.OutOfMemoryError!
- int m= Integer.parseInt(str.charAt(i))??
- java中 import java.awt.* *的含义
- 关于环境变量的作用请教
- 如何显示彩色文本?
- 在java中,怎样使用另外一个类中的对象…………在线等
- 我想每两分钟执行一段代码,怎么控制呢?
- 我想用java作一个每隔一段时间就提醒我休息的小东西,请大家提示一下该如何下手
- Document for difference between java and c++ ?
- awt和swing现在还用的着吗?
- 这条查询语句哪里错了
{
private static int MAX_THREAD = 10000;
private static int threadCount = 0;
public SimpleThread() {
++threadCount;
System.out.println("Making " + threadCount);
}
public void run() {
while(true) {
try {
sleep(1000);
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception{
for(int i = 0; i < MAX_THREAD; i++)
new SimpleThread().start();
}
} 我用10000 但是运行到7000多时候就内存溢出了. 你可以测试一下你的机器.适当增加线程数.
{
public static boolean flag = false;
private static int MAX_THREAD = 10000;
private static int threadCount = 0;
public SimpleThread() {
++threadCount;
System.out.println("Making " + threadCount);
}
public void run() {
while(true) {
try {
sleep(1000);
if (flag)
{
//System.out.println("Thread Destroy:" + (--threadCount));
break;
}
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
public static void main(String[] args)
{
int i = 0;
try {
for(; i < MAX_THREAD; i++)
new SimpleThread().start();
}catch (Throwable e)
{
System.out.println("最大线程是:"+ (i+1));
//e.printStackTrace();
flag = true;
}
}
} ... ...Making 7229
Making 7230
Making 7231
Making 7232
Making 7233
最大线程是:7233F:\>