01: /*
02: * TestInterpThreadContextClassCmd.java --
03: *
04: * This file tests changing an argument object's internal
05: * rep to TclList.
06: *
07: * Copyright (c) 2002 by Mo DeJong
08: *
09: * See the file "license.terms" for information on usage and redistribution
10: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11: *
12: * RCS: @(#) $Id: TestInterpThreadContextClassCmd.java,v 1.2 2006/04/13 07:36:51 mdejong Exp $
13: */
14:
15: package tests;
16:
17: import tcl.lang.*;
18:
19: public class TestInterpThreadContextClassCmd implements Command,
20: Runnable {
21: static boolean done;
22: static boolean ok;
23:
24: public void cmdProc(Interp interp, TclObject[] objv)
25: throws TclException {
26: if (objv.length != 1) {
27: throw new TclNumArgsException(interp, 1, objv, "");
28: }
29:
30: /* Create a new Thread and setup a context loader for it */
31:
32: Thread t = new Thread(this );
33:
34: done = false;
35: ok = false;
36:
37: // Setup specific class loader that should be used *before*
38: // the TclClassLoader when searching for resources. This
39: // loader uses the system loader as a parent.
40:
41: t.setContextClassLoader(new TestInterpThreadClassLoader(
42: ClassLoader.getSystemClassLoader()));
43: t.setName("TestInterpThread");
44: t.start();
45:
46: while (!done) {
47: try {
48: Thread.yield();
49: Thread.sleep(100);
50: } catch (Exception e) {
51: }
52: }
53:
54: if (ok) {
55: interp.setResult("OK");
56: } else {
57: interp.setResult("NOPE");
58: }
59: return;
60: }
61:
62: public void run() {
63: try {
64: //System.out.println("HELLO FROM THREAD");
65:
66: Interp interp = new Interp();
67: ClassLoader loader = interp.getClassLoader();
68:
69: Class c = null;
70: try {
71: c = loader.loadClass("TestInterpThreadUnknown");
72: } catch (ClassNotFoundException e) {
73: } catch (PackageNameException e) {
74: }
75:
76: if (c != null) {
77: ok = true;
78: //System.out.println("LOADED " + c.getName() + " IN THREAD");
79: }
80:
81: interp.dispose();
82:
83: //System.out.println("GOODBYE FROM THREAD");
84: } finally {
85: done = true;
86: }
87: }
88: }
|