pom.xml加入
9 v8 b1 x0 Q5 c. k, v9 B! r0 {2 c" m( { ~
<dependency> <groupId >net.sourceforge.groboutils </groupId > <artifactId >groboutils-core</ artifactId> <version >5 </version > <scope >system </scope > <!--本地jar的路径,相对或者绝对都可以 --> <systemPath >D:\ groboutils-core-5.jar</systemPath > </dependency > ! p' G# g& l$ U
@Test1 F6 V/ E4 v. i k% o
public void MultiRequestsTest() {
( v9 M9 `/ ~! M! g3 N: { // 构造一个Runner
5 ~1 C k; h) N* [3 a, L TestRunnable runner = new TestRunnable() {
9 k X! x4 E9 u: B& f+ Y& [0 C @ @Override
$ B7 N1 @1 K p' w, N6 K$ w& Q8 X& l public void runTest() throws Throwable {! ^ t' S) y, Z; D
// 测试内容
: P: g. X( E8 o. J: s' l& ^+ X2 i* @& N
3 h( }% t8 Y! T }
" { W* U; H+ R, q, W };# g. h( I. P) F' G! i* e6 a
int runnerCount = 1000;
2 \' R4 s* `7 A9 {1 Y9 V // Rnner数组,想当于并发多少个。
( d! R9 v8 c/ S. d& ^0 _ TestRunnable[] trs = new TestRunnable
|& W( Y8 V* d2 z) t! Z, H+ j6 C6 p, C9 c
[runnerCount];
: g' @* h. I) Z+ m3 T for (int i = 0; i < runnerCount; i++) {
- X' h; p) p- R: M trs = runner;6 ]% y% l; y1 }6 H# }. [
}: Y- M4 M9 |* }5 T( a3 a
// 用于执行多线程测试用例的Runner,将前面定义的
" I" y/ @7 [! D4 ` W2 |
% a) ]! l! ~1 W" w2 l& V& h1 K单个Runner组成的数组传入" S* t, B+ V/ Y# E5 o2 u& c! B
MultiThreadedTestRunner mttr = new
5 C& h6 o9 G- x3 w' \" j9 g
@9 ]# t' }6 \4 e+ aMultiThreadedTestRunner(trs);
. ` h! C; ]8 \" s0 ? try {5 g$ ?+ ?) H$ I* g4 f' G5 l
// 开发并发执行数组里定义的内容
# Q* a2 @1 {* M7 `3 |- q mttr.runTestRunnables();. S) o! o z0 k$ E" z/ e
} catch (Throwable e) {; L! I- k+ z, t. ^; p
e.printStackTrace();4 z) _: t) O) h' L/ _
}
# ]7 e- d( R7 }* S" r }
% ~ ^6 u" W: ?# z4 f
3 b7 B9 [& \3 d! m) Y( d. Kgroboutils-core-5.jar百度网盘下载地址:java自学网(javazx.com)groboutils-core-5.jar.zip【密码回帖可见】
$ i8 Q. ~& F" y# E G3 O
# G( S. I, ]7 z _3 [4 _2 L0 U7 z. G* H! V& g5 p: b+ Z& a- T
; X: U7 o7 U1 ^1 O( D" F) r+ ?$ g
, ^) `2 x, C4 p; k% {
|