|
1 /* |
|
2 * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /** |
|
25 * Test Java Program |
|
26 * |
|
27 * @author Daryl Puryear |
|
28 * @copyright 1999-2004 Wily Technology, Inc. All rights reserved. |
|
29 */ |
|
30 public class ParallelTransformerLoaderApp |
|
31 { |
|
32 private static final int kNumIterations = 1000; |
|
33 |
|
34 public static void |
|
35 main( String[] args) |
|
36 throws Exception |
|
37 { |
|
38 System.out.println(); |
|
39 System.out.print("Starting test with " + kNumIterations + " iterations"); |
|
40 for (int i = 0; i < kNumIterations; i++) |
|
41 { |
|
42 // load some classes from multiple threads (this thread and one other) |
|
43 Thread testThread = new TestThread(2); |
|
44 testThread.start(); |
|
45 loadClasses(1); |
|
46 |
|
47 // log that it completed and reset for the next iteration |
|
48 testThread.join(); |
|
49 System.out.print("."); |
|
50 ParallelTransformerLoaderAgent.generateNewClassLoader(); |
|
51 } |
|
52 |
|
53 System.out.println(); |
|
54 System.out.println("Test completed successfully"); |
|
55 } |
|
56 |
|
57 private static class TestThread |
|
58 extends Thread |
|
59 { |
|
60 private final int fIndex; |
|
61 |
|
62 public |
|
63 TestThread( int index) |
|
64 { |
|
65 super("TestThread"); |
|
66 |
|
67 fIndex = index; |
|
68 } |
|
69 |
|
70 public void |
|
71 run() |
|
72 { |
|
73 loadClasses(fIndex); |
|
74 } |
|
75 } |
|
76 |
|
77 public static void |
|
78 loadClasses( int index) |
|
79 { |
|
80 ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader(); |
|
81 try |
|
82 { |
|
83 Class.forName("TestClass" + index, true, loader); |
|
84 } |
|
85 catch (Exception e) |
|
86 { |
|
87 e.printStackTrace(); |
|
88 } |
|
89 } |
|
90 } |