Path: blob/master/test/jdk/java/beans/XMLEncoder/Test4822050.java
41152 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 482205026* @run main/timeout=1000 Test482205027* @summary Tests concurrent decoding28* @author Sergey Malenkov29*/3031import java.beans.ExceptionListener;32import java.beans.XMLDecoder;33import java.beans.XMLEncoder;3435import java.io.ByteArrayInputStream;36import java.io.ByteArrayOutputStream;3738import javax.swing.JLabel;3940public class Test4822050 implements ExceptionListener, Runnable {41private static final int THREADS = 40;42private static final int ATTEMPTS = 100;4344public static void main(String[] args) throws Exception {45ByteArrayOutputStream baos = new ByteArrayOutputStream();46XMLEncoder encoder = new XMLEncoder(baos);47encoder.writeObject(new JLabel("hello")); // NON-NLS: test message48encoder.close();4950byte[] buffer = baos.toByteArray();51for (int i = 0; i < THREADS; i++)52start(buffer);53}5455private static void start(byte[] buffer) {56Thread thread = new Thread(new Test4822050(buffer));57thread.start();58}596061private byte[] buffer;6263public Test4822050(byte[] buffer) {64this.buffer = buffer;65}6667public void exceptionThrown(Exception exception) {68throw new Error(exception);69}7071public void run() {72for (int i = 0; i < ATTEMPTS; i++)73parse();74}7576private void parse() {77XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(this.buffer));78decoder.readObject();79decoder.close();80}81}828384