怎样写一个测试支持最大线程的程序,十分着急,谢谢! 想测试一下平台支持的最大的线程数,想知道有没有这样的示例程序。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class SimpleThread extends Thread { 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多时候就内存溢出了. 你可以测试一下你的机器.适当增加线程数. 十分谢谢!可为什莫我捕获不到java.lang.OutOfMemoryError异常。 public class SimpleThread extends Thread { 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 7229Making 7230Making 7231Making 7232Making 7233最大线程是:7233F:\> 用 Throwable 捕获.OutOfMemoryError 不属于Exception 范围 Thanks, I will test it later.I sent a PM to you, please check! 刚学习JAVA很茫然,请前辈指点 菜鸟求助 关于ImageIcon() JTree 的分层模糊查找 java怎么调用外部的ppt文件?如果想将ppt内嵌到内容面板上怎么解决? 设计中国银行网站 简单的画图问题 java里怎么知道一个file的大小? help File 在tomcat里创建自己的目录 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:\>