Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/text/Format/DateFormat/Bug4407042.java
48795 views
1
/*
2
* Copyright (c) 2001, 2016, 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 4407042
27
* @summary Make sure that cloned SimpleDateFormat objects work
28
* independently in multiple threads.
29
* @run main Bug4407042 10
30
*/
31
32
import java.io.*;
33
import java.text.*;
34
import java.util.*;
35
36
// Usage: java Bug4407042 [duration]
37
public class Bug4407042 {
38
39
static final String TIME_STRING = "2000/11/18 00:01:00";
40
static final long UTC_LONG = 974534460000L;
41
static SimpleDateFormat masterFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
42
static boolean runrun = true;
43
static int duration = 100;
44
45
void test() {
46
Locale locale = Locale.getDefault();
47
if (locale.equals(new Locale("th", "TH")) ||
48
locale.equals(new Locale("hi", "IN"))) {
49
return;
50
}
51
52
masterFormat.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
53
DateParseThread d1 = new DateParseThread();
54
DateFormatThread d2 = new DateFormatThread();
55
d1.start();
56
d2.start();
57
int n = Thread.activeCount();
58
boolean failed = false;
59
60
for (int i = 0; i < duration; i++) {
61
try {
62
Thread.sleep(1000);
63
if (Thread.activeCount() != n) {
64
failed = true;
65
break;
66
}
67
} catch (InterruptedException e) {
68
}
69
}
70
runrun = false;
71
try {
72
d1.join();
73
d2.join();
74
} catch (InterruptedException e) {
75
}
76
if (failed) {
77
throw new RuntimeException("Failed");
78
}
79
}
80
81
synchronized static SimpleDateFormat getFormatter() {
82
return (SimpleDateFormat) masterFormat.clone();
83
}
84
85
static class DateParseThread extends Thread {
86
public void run() {
87
SimpleDateFormat sdf = getFormatter();
88
Calendar cal = null;
89
90
try {
91
int i = 0;
92
while (runrun) {
93
Date date =sdf.parse(TIME_STRING);
94
long t = date.getTime();
95
i++;
96
if (t != UTC_LONG) {
97
throw new RuntimeException("Parse Error: " + i +
98
" (" + sdf.format(date) + ") " + t +
99
" != " + UTC_LONG);
100
}
101
}
102
} catch (ParseException e) {
103
e.printStackTrace();
104
throw new RuntimeException("Parse Error");
105
}
106
}
107
}
108
109
static class DateFormatThread extends Thread {
110
public void run () {
111
SimpleDateFormat sdf = getFormatter();
112
Calendar cal = null;
113
114
int i = 0;
115
while (runrun) {
116
i++;
117
String s = sdf.format(new Date(UTC_LONG));
118
if (!s.equals(TIME_STRING)) {
119
throw new RuntimeException("Format Error: " + i + " " +
120
s + " != " + TIME_STRING);
121
}
122
}
123
}
124
}
125
126
public static void main (String[] args) {
127
if (args.length == 1) {
128
duration = Math.max(10, Integer.parseInt(args[0]));
129
}
130
new Bug4407042().test();
131
}
132
}
133
134