1 /* |
|
2 * Copyright (c) 2009, 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 import java.io.*; |
|
24 import javax.xml.parsers.DocumentBuilderFactory; |
|
25 import java.security.*; |
|
26 |
|
27 public class Deadlock2 { |
|
28 public static void main(String[] args) throws Exception { |
|
29 File file = new File("object.tmp"); |
|
30 final byte[] bytes = new byte[(int) file.length()]; |
|
31 FileInputStream fileInputStream = new FileInputStream(file); |
|
32 int read = fileInputStream.read(bytes); |
|
33 if (read != file.length()) { |
|
34 throw new Exception("Didn't read all"); |
|
35 } |
|
36 Thread.sleep(1000); |
|
37 |
|
38 Runnable xmlRunnable = new Runnable() { |
|
39 public void run() { |
|
40 try { |
|
41 DocumentBuilderFactory.newInstance(); |
|
42 } catch (Exception e) { |
|
43 e.printStackTrace(); |
|
44 } |
|
45 } |
|
46 }; |
|
47 |
|
48 Runnable readObjectRunnable = new Runnable() { |
|
49 public void run() { |
|
50 try { |
|
51 ObjectInputStream objectInputStream = |
|
52 new ObjectInputStream(new ByteArrayInputStream(bytes)); |
|
53 Object o = objectInputStream.readObject(); |
|
54 System.out.println(o.getClass()); |
|
55 } catch (Exception e) { |
|
56 e.printStackTrace(); |
|
57 } |
|
58 } |
|
59 }; |
|
60 |
|
61 Thread thread1 = new Thread(readObjectRunnable, "Read Object"); |
|
62 Thread thread2 = new Thread(xmlRunnable, "XML"); |
|
63 |
|
64 thread1.start(); |
|
65 thread2.start(); |
|
66 |
|
67 thread1.join(); |
|
68 thread2.join(); |
|
69 } |
|
70 } |
|