1 /* 2 * Copyright (c) 2014, 2015, 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 stream; 25 26 import java.io.FileInputStream; 27 import java.io.FileOutputStream; 28 import java.io.InputStream; 29 import java.io.OutputStream; 30 31 import javax.xml.stream.XMLInputFactory; 32 import javax.xml.stream.XMLOutputFactory; 33 import javax.xml.stream.XMLStreamReader; 34 import javax.xml.stream.XMLStreamWriter; 35 36 import org.testng.Assert; 37 import org.testng.annotations.Test; 38 39 /* 40 * @bug 6688002 41 * @summary Test single instance of XMLOutputFactory/XMLInputFactory create multiple Writer/Readers in parallel. 42 */ 43 public class Bug6688002Test { 44 45 private static final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); 46 private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); 47 private static final int NO_THREADS = 3; 48 49 @Test 50 public void testMultiThread() throws Exception { 51 Thread[] threads = new Thread[NO_THREADS]; 52 for (int i = 0; i < NO_THREADS; i++) { 53 threads[i] = new Thread(new MyRunnable(i)); 54 } 55 for (int i = 0; i < NO_THREADS; i++) { 56 threads[i].start(); 57 } 58 for (int i = 0; i < NO_THREADS; i++) { 59 threads[i].join(); 60 } 61 } 62 63 public class MyRunnable implements Runnable { 64 final int no; 65 66 MyRunnable(int no) { 67 this.no = no; 68 } 69 70 public void run() { 71 try { 72 FileOutputStream fos = new FileOutputStream("" + no); 73 XMLStreamWriter w = getWriter(fos); 74 // System.out.println("Writer="+w+" Thread="+Thread.currentThread()); 75 w.writeStartDocument(); 76 w.writeStartElement("hello"); 77 for (int j = 0; j < 50; j++) { 78 w.writeStartElement("a" + j); 79 w.writeEndElement(); 80 } 81 w.writeEndElement(); 82 w.writeEndDocument(); 83 w.close(); | 1 /* 2 * Copyright (c) 2014, 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 package stream; 25 26 import java.io.FileInputStream; 27 import java.io.FileOutputStream; 28 import java.io.InputStream; 29 import java.io.OutputStream; 30 31 import javax.xml.stream.XMLInputFactory; 32 import javax.xml.stream.XMLOutputFactory; 33 import javax.xml.stream.XMLStreamReader; 34 import javax.xml.stream.XMLStreamWriter; 35 36 import org.testng.Assert; 37 import org.testng.annotations.Listeners; 38 import org.testng.annotations.Test; 39 40 /* 41 * @bug 6688002 42 * @summary Test single instance of XMLOutputFactory/XMLInputFactory create multiple Writer/Readers in parallel. 43 */ 44 @Listeners({jaxp.library.FilePolicy.class}) 45 public class Bug6688002Test { 46 47 private static final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); 48 private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); 49 private static final int NO_THREADS = 3; 50 51 @Test 52 public void testMultiThread() throws Exception { 53 Thread[] threads = new Thread[NO_THREADS]; 54 for (int i = 0; i < NO_THREADS; i++) { 55 threads[i] = new Thread(new MyRunnable(i)); 56 } 57 for (int i = 0; i < NO_THREADS; i++) { 58 threads[i].start(); 59 } 60 for (int i = 0; i < NO_THREADS; i++) { 61 threads[i].join(); 62 } 63 } 64 65 @Listeners({jaxp.library.BasePolicy.class}) 66 public class MyRunnable implements Runnable { 67 final int no; 68 69 MyRunnable(int no) { 70 this.no = no; 71 } 72 73 public void run() { 74 try { 75 FileOutputStream fos = new FileOutputStream("" + no); 76 XMLStreamWriter w = getWriter(fos); 77 // System.out.println("Writer="+w+" Thread="+Thread.currentThread()); 78 w.writeStartDocument(); 79 w.writeStartElement("hello"); 80 for (int j = 0; j < 50; j++) { 81 w.writeStartElement("a" + j); 82 w.writeEndElement(); 83 } 84 w.writeEndElement(); 85 w.writeEndDocument(); 86 w.close(); |