多线程执行Rumtime.exec遇到的问题

在启动多线程对一个网段执行ping命令时,当线程数开到200以上,就很容易报如下异常:
引用

java.io.IOException: Cannot run program "ping": CreateProcess error=8, ?洢???×???¨???í
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at pingTest.SynPingTest.run(SynPingTest.java:68)
Caused by: java.io.IOException: CreateProcess error=8, ?洢???×???¨???í
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more


不知道为什么,是jvm不能同时执行多个process,还是不能同时执行多个ping命令?
贴上代码:

package pingTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SynPingTest extends Thread
{
    protected static Runtime rt = Runtime.getRuntime();
    
    private int ip = 1;
    
    public SynPingTest(int i)
    {
    	this.ip = i;
    }

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        for (int i = 0; i <= 200; i++)
        {
            SynPingTest spt1 = new SynPingTest(i);
            spt1.start();
            SynPingTest spt2 = new SynPingTest(i);
            spt2.start();
            /*try
            {
                sleep(100);
            }
            catch (InterruptedException e)
            {
            }*/
        }

    }

    @Override
    public void run()
    {
        Process p = null;
        try
        {
        	String ipAddr = "192.168.0." + ip;
            p = rt.exec("ping -a -w 300 -n 10 " + ipAddr);

            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(p.getInputStream()));
            String s = null;

            while ((s = bufferedReader.readLine()) != null)
            {
                if (!"".equals(s))
                {
                	if (s.indexOf("数据包") > -1 || s.indexOf("最短") > -1) {
						System.out.println(ipAddr + "  " + s);
					}
                }
            }
            p.destroy();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            if(p!=null)
                p.destroy();
        }
    }

}


你可能感兴趣的:(多线程执行Rumtime.exec遇到的问题)