Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
建模客户端-线程交错Java_Java_Multithreading_Concurrency_Client Server_Emulation - Fatal编程技术网

建模客户端-线程交错Java

建模客户端-线程交错Java,java,multithreading,concurrency,client-server,emulation,Java,Multithreading,Concurrency,Client Server,Emulation,我试图通过模拟连接到服务器的多个客户机来对客户机/服务器系统进行压力测试。每个客户端都有一个线程。但是,当我运行以下代码(ClientStartEmulator()表示客户机)时,线程按顺序运行,而不是并发运行。(尽管在每个模拟客户端中都有多个线程产量和睡眠)。你知道怎么了吗 另一种方法是对每个jar进行系统调用,但这会很烦人,因为(这里没有显示),我会对返回的数组进行一些处理 谢谢 ClientStartEmulator emu = new ClientStartEmulator();

我试图通过模拟连接到服务器的多个客户机来对客户机/服务器系统进行压力测试。每个客户端都有一个线程。但是,当我运行以下代码(ClientStartEmulator()表示客户机)时,线程按顺序运行,而不是并发运行。(尽管在每个模拟客户端中都有多个线程产量和睡眠)。你知道怎么了吗

另一种方法是对每个jar进行系统调用,但这会很烦人,因为(这里没有显示),我会对返回的数组进行一些处理

谢谢

ClientStartEmulator emu = new ClientStartEmulator();
    emu.start(7777, "localhost", "examplestore", "foobar", "signFiles", "foobar", true, time, max_length); 
    ArrayList results = new ArrayList() ; 
    for (int i = 0 ; i<nb_clients ; i++ ) {
        Thread client = new Thread() {
            public void run() {
                ClientStartEmulator emul = new ClientStartEmulator();
                try {
                    emul.start(7777, "localhost", "examplestore", "foobar",     "signFiles", "foobar", false, time, max_length);

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } 
            }
        };
        client.run(); 

    }
}
ClientStartEmulator emu=newclientstartemulator();
emu.start(7777,“localhost”,“examplestore”,“foobar”,“signFiles”,“foobar”,true,time,max_length);
ArrayList结果=新建ArrayList();

对于(int i=0;i您应该调用
client.start()
,它在后台启动线程。通过调用
client.run()
您正在调用线程中执行run方法。我假定这不是您想要的

线程
代码:

/**
 * Causes this thread to begin execution; the Java Virtual Machine 
 * calls the <code>run</code> method of this thread. 
 * <p>
 * The result is that two threads are running concurrently: the 
 * current thread (which returns from the call to the 
 * <code>start</code> method) and the other thread (which executes its 
 * <code>run</code> method). 
 * ...
 */
public synchronized void start() {
   ...

start()
方法创建本机线程并返回,而新线程调用
thread.run()
方法。

您应该调用
client.start()
,它在后台启动线程。通过调用
client.run()
您正在调用线程中执行run方法。我认为这不是您想要的

线程
代码:

/**
 * Causes this thread to begin execution; the Java Virtual Machine 
 * calls the <code>run</code> method of this thread. 
 * <p>
 * The result is that two threads are running concurrently: the 
 * current thread (which returns from the call to the 
 * <code>start</code> method) and the other thread (which executes its 
 * <code>run</code> method). 
 * ...
 */
public synchronized void start() {
   ...

start()
方法创建本机线程并返回,而新线程调用
thread.run()
方法。

start
调用
run
,因此,不要使用
client.run()
替换为
client.start()
client.start()