@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();
}
}
}
java代码线程压力测试
最新推荐文章于 2024-07-28 03:14:18 发布