LR使用java vuser协议.不能直接在Vuser脚本编辑里面使用多线程吗?
下面是例子import lrapi.lr;
class test1 extends Thread{
public void run(){
for(int a=0;a<50;a++)
System.out.println("a="+a);
}
}
class test2 extends Thread{
public void run(){
for(int i=50;i>0;i--)
System.out.println("i="+i);
}
}
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
test1 t1=new test1();
test2 t2=new test2();
t1.start();
t2.start();
// t1.run();
// t2.run();
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
为什么执行后没有打印出内容?直接就运行完了.看log里面报错 Error (-17998): Failed to get thread TLS entry 不明白是什么意思.
代码在别的环境下 比如Eclipse 能正常执行并打印出结果?? 在lr中通过调用java class文件也不行.在lr中F5就直接运行完了,也没有打印出内容.然后log里面有错误
Error (-17998): Failed to get thread TLS entry.
是不是Vuser不能使用多线程的方式?或是Vuser不支持java的多线程?还是我使用的方法不当?
package thread.test;
public class test3 extends Thread{
private int a=0;
public void run(){
for(a=0;a<50;a++){
System.out.println(currentThread().getName()+":"+a);
try{
sleep(100);
}catch(InterruptedException e){throw new RuntimeException(e);}
}
}
}
lr脚本
import lrapi.lr;
import thread.test.*;
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
test3 t3=new test3();
t3.start();
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
} t1.run();
t2.run();
可以打印出
回复 3# 的帖子
Thread类的run()方法是专门给自身的线程执行的..如果用主线程调用run()方法那不感觉很奇怪?只有调用start方法 线程才会进入就绪状态吧... import lrapi.lr;class test1 extends Thread{
public void run(){
for(int a=0;a<50;a++)
System.out.println("a="+a);
}
}
class test2 extends Thread{
public void run(){
for(int i=50;i>0;i--)
System.out.println("i="+i);
}
}
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
test1 t1=new test1();
test2 t2=new test2();
t1.run();
t2.run();
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
经测试完全可行,日志:
Starting action Actions.
System.out: a=0 Notify:
System.out: a=1 Notify:
System.out: a=2 Notify:
System.out: a=3 Notify:
System.out: a=4 Notify:
System.out: a=5 Notify:
System.out: a=6 Notify:
System.out: a=7 Notify:
System.out: a=8 Notify:
System.out: a=9 Notify:
System.out: a=10 Notify:
System.out: a=11 Notify:
System.out: a=12 Notify:
System.out: a=13 Notify:
System.out: a=14 Notify:
System.out: a=15 Notify:
System.out: a=16 Notify:
System.out: a=17 Notify:
System.out: a=18 Notify:
System.out: a=19 Notify:
System.out: a=20 Notify:
System.out: a=21 Notify:
System.out: a=22 Notify:
System.out: a=23 Notify:
System.out: a=24 Notify:
System.out: a=25 Notify:
System.out: a=26 Notify:
System.out: a=27 Notify:
System.out: a=28 Notify:
System.out: a=29 Notify:
System.out: a=30 Notify:
System.out: a=31 Notify:
System.out: a=32 Notify:
System.out: a=33 Notify:
System.out: a=34 Notify:
System.out: a=35 Notify:
System.out: a=36 Notify:
System.out: a=37 Notify:
System.out: a=38 Notify:
System.out: a=39 Notify:
System.out: a=40 Notify:
System.out: a=41 Notify:
System.out: a=42 Notify:
System.out: a=43 Notify:
System.out: a=44 Notify:
System.out: a=45 Notify:
System.out: a=46 Notify:
System.out: a=47 Notify:
System.out: a=48 Notify:
System.out: a=49 Notify:
System.out: i=50 Notify:
..................... 好像 Vgen不识别Thread类的start() 方法
直接调用为空 基于Loadrunner平台Socket协议的JavaVuser(多线程)
http://blog.csdn.net/captain_gbt/article/details/7209570 回复 1# orceric 基于Loadrunner平台Socket协议的JavaVuser(多线程)
http://blog.csdn.net/captain_gbt/article/details/7209570
不要在lr里面做java的多线程推荐 不要在lr里面做java的多线程推荐
云层 发表于 2012-1-19 10:41 http://bbs.51testing.com/images/common/back.gif
为什么?LR的多线程,是怎么实现的。是每个Vuser一个线程,之后用户的多个action,还会加线程吗?
页:
[1]