-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientTest1.java
More file actions
69 lines (47 loc) · 1.69 KB
/
Copy pathClientTest1.java
File metadata and controls
69 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.*;
class ClientRunTest implements Runnable {
ClientRunTest() {}
public void run() {
final int requests = 500;
final Random rand = new Random();
/* request = "Action,Client1,Amount,Client2"; */
int action_nr, amount, cId1, cId2, answer;
char action;
try {
for (int request_id = 0; request_id < requests; request_id++) {
Thread.sleep(rand.nextInt(10));
action_nr = rand.nextInt(4);
amount = rand.nextInt(20) + 1;
cId1 = rand.nextInt(ClientTest1.cThreads);
cId2 = rand.nextInt(ClientTest1.cThreads);
switch (action_nr) {
case 0:
action = '+';
//balance = balance + amount;
break;
case 1:
action = '-';
//balance = balance - amount;
break;
case 2:
action = '>';
//balance = balance - amount;
break;
default:
action = '?';
break;
}
new Thread(new ClientRun(cId1, action, amount, cId2 )).start();
//System.out.println("Client " + cId1 + ", Request " + request + " to Server " + sId);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class ClientTest1 {
final static int cThreads = 20;
public static void main(String[] args) {
new Thread(new ClientRunTest()).start();
}
}