java代码线程压力测试

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:META-INF/spring/spring-config.xml" })
public class TestOrderTrace {
    @Autowired
    private IOrderService orderService;// 订单服务接口
    @Autowired
    private IOrderTraceService orderTraceService;// 订单流水服务接口

    @Test
    public void TestGenerateOrder() throws Exception {
        System.out
                .println("-----------------------------测试开始-----------------------------");
        Date start = new Date();
        orderTraceService.TestGenerateOrder("");
        System.out
                .println("------------------------------测试结束------------------------------");
        Date end = new Date();

    }

    @Test
    public void Timetest() throws ParseException {
        Date now = new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d1 = df.parse("2004-03-26 13:31:40");
        Date d2 = df.parse("2004-01-02 11:30:24");
        long diff = d1.getTime() - d2.getTime();
        long days = diff / (1000 * 60 * 60 * 24);
        System.out.println(days + "++++++++++++++++++++++++++++++++++++++");

    }

    public static int getSeconds(Date startdate, Date enddate) {
        long time = enddate.getTime() - startdate.getTime();
        int totalS = new Long(time / 1000).intValue();
        return totalS;
    }

    public class ThreadTest extends Thread {
        int i = 0;

        // 重写run方法,run方法的方法体就是现场执行体
        public void run() {
//          for (;i<3; i++) {
//              System.out.println(getName() + "  " + i);
            orderTraceService.TestGenerateOrder("aa"+i);
            i++;
//
//          }
        }

        public void m() {
            for (int i = 0; i < 50; i++) {//这里循环的是线程数
                System.out.println(Thread.currentThread().getName()
                        + "**********************************: " + i);

                new ThreadTest().start();
                // new ThreadTest().start();

            }
        }

    }
//以下是测试方法,开始测试用这个
    @Test
    public void TestTimeThread() {
        Date start = new Date();
        ThreadTest t = new ThreadTest();
        Date end = new Date();
        int seconds = getSeconds(start, end);
        while (getSeconds(start, end) < 3600) {
        //这里是以秒为单位的时间,表示循环测试的时间
            end = new Date();
            t.m();
        }
    }

}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值