source:
src/benchmark/schedint/JavaThread.java
@
5510027
Last change on this file since 5510027 was 56de6b39, checked in by , 7 years ago | |
---|---|
|
|
File size: 779 bytes |
Rev | Line | |
---|---|---|
[56de6b39] | 1 | class Monitor { |
2 | public static volatile Boolean go = false; | |
3 | } | |
[6aa537a4] | 4 | |
[56de6b39] | 5 | class Signaller extends Thread { |
6 | Monitor m; | |
7 | Signaller(Monitor m) { | |
8 | this.m = m; | |
9 | } | |
[6aa537a4] | 10 | |
[56de6b39] | 11 | public void run() { |
12 | Monitor.go = true; | |
13 | while( Monitor.go ) { | |
14 | synchronized(this.m) { | |
15 | this.m.notify(); | |
[6aa537a4] | 16 | } |
17 | } | |
18 | } | |
[56de6b39] | 19 | } |
[6aa537a4] | 20 | |
[56de6b39] | 21 | public class JavaThread { |
[6aa537a4] | 22 | public static void main(String[] args) throws InterruptedException { |
23 | int NoOfTimes = 50000; | |
[56de6b39] | 24 | Monitor m = new Monitor(); |
25 | long start, end; | |
26 | Signaller s = new Signaller(m); | |
27 | synchronized(m) { | |
28 | s.start(); | |
29 | while( !Monitor.go ) { | |
30 | Thread.yield(); | |
31 | } | |
32 | start = System.nanoTime(); | |
33 | for(int i = 1; i <= NoOfTimes; i += 1) { | |
34 | m.wait(); | |
35 | } | |
36 | end = System.nanoTime(); | |
[6aa537a4] | 37 | } |
[56de6b39] | 38 | Monitor.go = false; |
[6aa537a4] | 39 | s.join(); |
40 | System.out.println( (end - start) / NoOfTimes); | |
41 | } | |
42 | } |
Note: See TracBrowser
for help on using the repository browser.