Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadMXBean/BarrierHandler.java
40948 views
1
/*
2
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package nsk.monitoring.ThreadMXBean;
25
26
import java.util.concurrent.*;
27
28
/**
29
* Provide synchronization between management thread and its
30
* managed threads.
31
*/
32
public class BarrierHandler {
33
34
/**
35
* CyclicBarries for internal synchronization
36
*/
37
private CyclicBarrier monitoredThreadsBarrier, startActionBarrier,
38
finishActionBarrier;
39
40
/**
41
* Creates new BarrierHandler that will match specified Threads with
42
* management threads
43
*
44
* @param threads managed threads that are handled by BarrierHandler
45
*/
46
public BarrierHandler(MXBeanTestThread... threads) {
47
startActionBarrier = new CyclicBarrier(2);
48
finishActionBarrier = new CyclicBarrier(2);
49
monitoredThreadsBarrier = new CyclicBarrier(threads.length, new ActionThread());
50
}
51
52
/**
53
* Waits when managed thread completes iteration and some action should
54
* be performed by management thread. Should be called within managed thread
55
* only.
56
*
57
*/
58
public void ready() {
59
try {
60
monitoredThreadsBarrier.await();
61
} catch (Exception ignored) {}
62
}
63
64
/**
65
* Allows managed threads to proceed to next iteration. Should be called
66
* within management thread only.
67
*/
68
public void proceed() {
69
try {
70
finishActionBarrier.await();
71
startActionBarrier.await();
72
} catch (Exception ignored) {}
73
}
74
75
/**
76
* Waits until all managed threads complete first iteration. Should be
77
* called within management thread only.
78
*/
79
public void start() {
80
try {
81
startActionBarrier.await();
82
} catch (Exception ignored) {}
83
}
84
85
/**
86
* Allows managed threads to finish after last iteration. Should be called
87
* within management thread only.
88
*/
89
public void finish() {
90
try {
91
finishActionBarrier.await();
92
} catch (Exception ignored) {}
93
}
94
95
/**
96
* Action performed on main barrier. Used for synchronization between
97
* management and managed threads
98
*/
99
private class ActionThread extends Thread {
100
@Override
101
public void run() {
102
try {
103
startActionBarrier.await();
104
finishActionBarrier.await();
105
} catch (Exception ignored) {}
106
}
107
}
108
}
109
110