pom.xml加入
, F1 q3 C8 O) c+ E* W9 [" b" [2 Z+ j+ x
<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 >
4 f8 t$ N$ D$ S) O, i b @Test+ `& \% j: \- U/ V; M0 a& w
public void MultiRequestsTest() {
9 k; {2 d5 j: T4 q& j // 构造一个Runner
& H* h1 k% v9 u" ^2 u% h TestRunnable runner = new TestRunnable() {# Q0 ~1 K9 j2 l9 }5 l1 j
@Override3 O" p1 e/ t. A; ?
public void runTest() throws Throwable {
4 D! }0 I0 b; \2 e // 测试内容
6 t+ |- `( b) B7 P7 A- D# ?3 D
* z6 O7 ]' s" K# m m. S, g7 E0 B
}1 z* G$ ]4 N0 r' S! g
};
) `9 L& N$ `4 Q& M int runnerCount = 1000;* E# Z3 s0 x7 U
// Rnner数组,想当于并发多少个。6 i1 M- K/ U; Q5 j+ D
TestRunnable[] trs = new TestRunnable( H. N+ p1 H1 B
; h: {! @5 m3 [9 L: Z/ Y[runnerCount];
, L4 U* m, x7 E4 H- g for (int i = 0; i < runnerCount; i++) {
: \* ~: V% ~' B& u trs = runner;
: ~. g0 @/ h! W, I }
6 N& U y1 U/ o! w // 用于执行多线程测试用例的Runner,将前面定义的
8 _+ t1 d9 Z8 _! J. d# Y) O
: ~4 v/ m+ x, s) c8 Z* y: i/ d, l单个Runner组成的数组传入; o6 n7 g+ a1 Y& Q. c' ~4 u6 S0 ^
MultiThreadedTestRunner mttr = new
5 d( c) I# G' \5 Q/ @; A- g
& ?5 I- u5 c0 [% ]: GMultiThreadedTestRunner(trs);
, i4 Q9 D9 q0 L3 B: z try {
* X9 t& }2 A5 Y( L5 ` // 开发并发执行数组里定义的内容- s0 K( s4 i A/ m# J {4 b1 h( U
mttr.runTestRunnables();3 O( v7 e7 l3 \) z
} catch (Throwable e) {
+ |( a8 c- O2 a% I# d% L1 t" W e.printStackTrace();0 D8 T/ g/ P r; O* Y" z- r
}
3 N- T# w6 e T+ ? }, C4 \- g! R5 z& Y' W
% c% }" j, T5 F+ wgroboutils-core-5.jar百度网盘下载地址:java自学网(javazx.com)groboutils-core-5.jar.zip【密码回帖可见】, K( I0 t7 U4 h( ~' {4 f
$ {" |' w! y. w% n& S$ n
) S5 G" E% t9 i# h4 s0 W( f; J% {# k2 h4 p
+ K; h/ v) ]/ [5 x2 X
|