51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4490|回复: 9
打印 上一主题 下一主题

[原创] LR使用java vuser协议.不能直接在Vuser脚本编辑里面使用多线程吗?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-4-12 15:40:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是例子
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 [param not passed in call] thread TLS entry 不明白是什么意思.
代码在别的环境下 比如Eclipse 能正常执行并打印出结果??
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2010-4-12 16:18:55 | 只看该作者
在lr中通过调用java class文件也不行.在lr中F5就直接运行完了,也没有打印出内容.然后log里面有错误
Error (-17998): Failed to get [param not passed in call] 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
}
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2010-4-12 16:44:31 | 只看该作者
t1.run();
        t2.run();

可以打印出
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2010-4-12 16:48:52 | 只看该作者

回复 3# 的帖子

Thread类的run()方法是专门给自身的线程执行的..如果用主线程调用run()方法那不感觉很奇怪?只有调用start方法 线程才会进入就绪状态吧...
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2010-4-12 16:49:55 | 只看该作者
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:
.....................
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2010-4-12 16:53:55 | 只看该作者
好像 Vgen  不识别Thread类的start() 方法

直接调用为空
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2012-1-18 18:30:13 | 只看该作者
基于Loadrunner平台Socket协议的JavaVuser(多线程)
http://blog.csdn.net/captain_gbt/article/details/7209570
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2012-1-18 18:30:22 | 只看该作者
回复 1# orceric 基于Loadrunner平台Socket协议的JavaVuser(多线程)
http://blog.csdn.net/captain_gbt/article/details/7209570
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2012-1-19 10:41:18 | 只看该作者
不要在lr里面做java的多线程推荐
回复 支持 反对

使用道具 举报

该用户从未签到

10#
发表于 2012-2-28 17:18:53 | 只看该作者
不要在lr里面做java的多线程推荐
云层 发表于 2012-1-19 10:41



    为什么?LR的多线程,是怎么实现的。是每个Vuser一个线程,之后用户的多个action,还会加线程吗?
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-23 07:29 , Processed in 0.090233 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表