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