1043N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1043N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1043N/A *
1043N/A * This code is free software; you can redistribute it and/or modify it
1043N/A * under the terms of the GNU General Public License version 2 only, as
1043N/A * published by the Free Software Foundation.
1043N/A *
1043N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1043N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1043N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1043N/A * version 2 for more details (a copy is included in the LICENSE file that
1043N/A * accompanied this code).
1043N/A *
1043N/A * You should have received a copy of the GNU General Public License version
1043N/A * 2 along with this work; if not, write to the Free Software Foundation,
1043N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1043N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1043N/A */
1043N/Aimport java.io.*;
1043N/Aimport javax.xml.parsers.DocumentBuilderFactory;
1043N/Aimport java.security.*;
1043N/A
1043N/Apublic class Deadlock2 {
1043N/A public static void main(String[] args) throws Exception {
1043N/A File file = new File("object.tmp");
1043N/A final byte[] bytes = new byte[(int) file.length()];
1043N/A FileInputStream fileInputStream = new FileInputStream(file);
1043N/A int read = fileInputStream.read(bytes);
1043N/A if (read != file.length()) {
1043N/A throw new Exception("Didn't read all");
1043N/A }
1043N/A Thread.sleep(1000);
1043N/A
1043N/A Runnable xmlRunnable = new Runnable() {
1043N/A public void run() {
1043N/A try {
1043N/A DocumentBuilderFactory.newInstance();
1043N/A } catch (Exception e) {
1043N/A e.printStackTrace();
1043N/A }
1043N/A }
1043N/A };
1043N/A
1043N/A Runnable readObjectRunnable = new Runnable() {
1043N/A public void run() {
1043N/A try {
1043N/A ObjectInputStream objectInputStream =
1043N/A new ObjectInputStream(new ByteArrayInputStream(bytes));
1043N/A Object o = objectInputStream.readObject();
1043N/A System.out.println(o.getClass());
1043N/A } catch (Exception e) {
1043N/A e.printStackTrace();
1043N/A }
1043N/A }
1105N/A };
1043N/A
1043N/A Thread thread1 = new Thread(readObjectRunnable, "Read Object");
1043N/A Thread thread2 = new Thread(xmlRunnable, "XML");
1043N/A
1043N/A thread1.start();
1043N/A thread2.start();
1043N/A
1043N/A thread1.join();
1043N/A thread2.join();
1043N/A }
1043N/A}