processclasslocktest.java
来自「基于LWVCL开发的库」· Java 代码 · 共 78 行
JAVA
78 行
/** * a test to ensure we do upcalls to static initializers properly. * * @author Godmar Back <gback@cs.utah.edu> */class LockBase { static { try { Thread.sleep(5000); } catch (Exception e) { System.out.println(e); } }}class Sub extends LockBase {}public class ProcessClassLockTest{ public static void main(String av[]) throws Exception { // a watchdog thread that kills us off after 2.5 sec new Thread() { public void run() { try { Thread.sleep(10000); System.out.println("sorry, you timed out"); System.exit(-1); } catch (Exception e) { System.out.println(e); } } }.start(); // a thread that will load Sub and LockBase new Thread() { public void run() { try { Class.forName("Sub"); } catch (Throwable t) { System.out.println(t); } } }.start(); // get thread 2 going Thread.sleep(1000); /* this thread should be unaffected by the fact that thread 2 * sleeps in the static initializer of LockBase */ Thread th; th = new Thread() { public void run() { try { Class.forName("this_class_does_not_exist"); } catch (Throwable t) { System.out.println(t.getClass().getName()+": "+t.getMessage().substring(0, 25)); } System.exit(0); } }; th.start(); try { th.join(); } catch (InterruptedException ie) { System.out.println("interrupted"); } }}/* Expected Output:java.lang.ClassNotFoundException: this_class_does_not_exist*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?