Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/ThreadGroup/SetMaxPriority.java
41149 views
1
/*
2
* Copyright (c) 2007, 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
/*
25
* @test
26
* @bug 4708197 6497629
27
* @summary Test for max priority setting that matches spec
28
* @author Pete Soper
29
*/
30
31
public class SetMaxPriority {
32
33
public static void main(String args[]) throws Exception {
34
ThreadGroup tg = new ThreadGroup("foo");
35
ThreadGroup ptg = tg.getParent();
36
int currentMaxPriority = tg.getMaxPriority();
37
int halfMaxPriority = ptg.getMaxPriority() / 2;
38
if (halfMaxPriority - Thread.MIN_PRIORITY < 2) {
39
throw new RuntimeException("SetMaxPriority test no longer valid: starting parent max priority too close to Thread.MIN_PRIORITY");
40
}
41
tg.setMaxPriority(halfMaxPriority - 2);
42
currentMaxPriority = tg.getMaxPriority();
43
if (currentMaxPriority != halfMaxPriority - 2) {
44
throw new RuntimeException("SetMaxPriority failed: max priority not changed");
45
}
46
47
// This will fail if bug 6497629 is present because the min tests is
48
// being made with the (just lowered) max instead of the parent max,
49
// preventing the priority from being moved back up.
50
tg.setMaxPriority(currentMaxPriority + 1);
51
int newMaxPriority = tg.getMaxPriority();
52
if (newMaxPriority != currentMaxPriority + 1) {
53
throw new RuntimeException("SetMaxPriority failed: defect 6497629 present");
54
}
55
56
// Confirm that max priorities out of range on both ends have no
57
// effect.
58
for (int badPriority : new int[] {Thread.MIN_PRIORITY - 1,
59
Thread.MAX_PRIORITY + 1}) {
60
int oldPriority = tg.getMaxPriority();
61
tg.setMaxPriority(badPriority);
62
if (oldPriority != tg.getMaxPriority())
63
throw new RuntimeException(
64
"setMaxPriority bad arg not ignored as specified");
65
}
66
67
System.out.println("SetMaxPriority passed");
68
}
69
}
70
71