pom.xml加入
8 @7 t$ x9 |& \: S! _' E( x9 B9 u! U/ U$ [. c
<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 M) K. ?9 a" {$ d C @Test
. ]7 X y) a6 s; w public void MultiRequestsTest() {
2 V( J/ T" P1 G4 R2 V) ]9 T // 构造一个Runner! f7 \' Z" E. c! u7 ^: A: m
TestRunnable runner = new TestRunnable() {8 a% w& k8 x: G4 _
@Override
4 D& m! Y6 N# s4 Q6 w* K# J6 s8 P6 s public void runTest() throws Throwable {- l, j- ]* {) T/ J! A- G5 d
// 测试内容* g4 [, i, O% l2 \
! i0 t$ R+ |/ L% M: S, z1 U+ ~( ^
& v4 v7 J& j$ y, J3 z0 w
}
! D7 n' [" x- ?5 W+ X$ k% s/ P }; f" w4 x; O. y# M- q( {" z: n
int runnerCount = 1000;
- k2 Q$ M/ G( `; A- \/ Z // Rnner数组,想当于并发多少个。" Z. L8 c: L) L+ x) J0 I6 x
TestRunnable[] trs = new TestRunnable9 Z% A n; v! N0 M2 I
% [% X* K/ X, ~$ M% h6 w8 O! t
[runnerCount];
+ l+ C- q [5 @. ` for (int i = 0; i < runnerCount; i++) {
) y! h6 _1 b$ A; L) c3 |* x9 ` trs = runner;1 z4 c& z& u8 S9 d8 l' n2 r; s
}) V3 k0 r( g3 R2 R. A
// 用于执行多线程测试用例的Runner,将前面定义的
5 t. R5 l9 v+ M
: j* O# P {0 V( c) m' N单个Runner组成的数组传入" i \! i! }* v# C6 M, ~
MultiThreadedTestRunner mttr = new
" v8 H0 J/ d1 t, r& M1 o9 |; D3 c* C5 w
MultiThreadedTestRunner(trs);
& x% q8 j6 i \3 N! j7 o# o# v. M try {( f# d; c) S1 ] T1 O. e
// 开发并发执行数组里定义的内容" v) T J0 y# b
mttr.runTestRunnables();0 x2 g' S4 s1 A2 B
} catch (Throwable e) {: ~' }3 E$ A5 N0 m! p" O
e.printStackTrace();
6 b. v: [. ^$ s) O0 I8 }5 G. l }" m* G5 A0 ~5 J1 n# z; U
}
+ u' \2 P- `& W1 [/ f8 s, `( l$ K, k, T3 y! g- d
groboutils-core-5.jar百度网盘下载地址:java自学网(javazx.com)groboutils-core-5.jar.zip【密码回帖可见】
6 y8 V* ?! S/ r2 q
3 |5 l. h$ o$ {4 F @$ E( ?4 S) i; c/ x! u! q% Q3 Z0 E" v
6 `; p8 Z p- c" x4 g* r1 R1 q
7 I6 {( |; t# ~/ S1 w1 w4 ] |