-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainClass.java
More file actions
84 lines (65 loc) · 1.95 KB
/
Copy pathMainClass.java
File metadata and controls
84 lines (65 loc) · 1.95 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.lang.*;
import popjava.annotation.POPClass;
@POPClass(isDistributable = false)
public class MainClass{
public static void main(String[] args){
System.out.println("Start broker-side semantic test ...");
System.out.println("-- Sequential call --");
MethodObj mo = new MethodObj();
mo.setSeq(1);
mo.setSeq(2);
mo.setSeq(3);
mo.setSeq(4);
int i=0;
while(i<4){
int crt = mo.get();
if(crt != i)
System.out.println("Sequential call failed");
else
System.out.println("Value should be " + crt +" // Value is "+ crt);
try{
Thread.sleep(1000);
} catch(InterruptedException e){
}
i++;
}
System.out.println("Value should be " + 4 +" // Value is "+ mo.get());
System.out.println("-- Concurrent call --");
mo.setConc(5);
mo.setConc(6);
mo.setConc(7);
mo.setConc(8);
try{
Thread.sleep(1500);
} catch(InterruptedException e){
}
int crt2 = mo.get();
if(crt2 != 8){
System.out.println("Concurrent call failed"+crt2);
}else{
System.out.println("Value should be " + 8 +" // Value is " + crt2);
}
System.out.println("-- Mutex call --");
mo.setMutex(10);
mo.setConc(20);
try{
Thread.sleep(1500);
} catch(InterruptedException e){
}
int crt3 = mo.get();
if(crt3 != 10)
System.out.println("Mutex call failed");
else
System.out.println("Value should be 10 // Value is "+crt3);
try{
Thread.sleep(3000);
} catch(InterruptedException e){
}
int crt4 = mo.get();
if(crt4 != 20)
System.out.println("Mutex call failed");
else
System.out.println("Value should be 20 // Value is "+crt4);
System.out.println("Broker-side semantic test ended...");
}
}