Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLEncoder/Test4822050.java
41152 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 4822050
27
* @run main/timeout=1000 Test4822050
28
* @summary Tests concurrent decoding
29
* @author Sergey Malenkov
30
*/
31
32
import java.beans.ExceptionListener;
33
import java.beans.XMLDecoder;
34
import java.beans.XMLEncoder;
35
36
import java.io.ByteArrayInputStream;
37
import java.io.ByteArrayOutputStream;
38
39
import javax.swing.JLabel;
40
41
public class Test4822050 implements ExceptionListener, Runnable {
42
private static final int THREADS = 40;
43
private static final int ATTEMPTS = 100;
44
45
public static void main(String[] args) throws Exception {
46
ByteArrayOutputStream baos = new ByteArrayOutputStream();
47
XMLEncoder encoder = new XMLEncoder(baos);
48
encoder.writeObject(new JLabel("hello")); // NON-NLS: test message
49
encoder.close();
50
51
byte[] buffer = baos.toByteArray();
52
for (int i = 0; i < THREADS; i++)
53
start(buffer);
54
}
55
56
private static void start(byte[] buffer) {
57
Thread thread = new Thread(new Test4822050(buffer));
58
thread.start();
59
}
60
61
62
private byte[] buffer;
63
64
public Test4822050(byte[] buffer) {
65
this.buffer = buffer;
66
}
67
68
public void exceptionThrown(Exception exception) {
69
throw new Error(exception);
70
}
71
72
public void run() {
73
for (int i = 0; i < ATTEMPTS; i++)
74
parse();
75
}
76
77
private void parse() {
78
XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(this.buffer));
79
decoder.readObject();
80
decoder.close();
81
}
82
}
83
84