01: /*
02: * Copyright (C) 2003-2007 Kepler Project.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining
05: * a copy of this software and associated documentation files (the
06: * "Software"), to deal in the Software without restriction, including
07: * without limitation the rights to use, copy, modify, merge, publish,
08: * distribute, sublicense, and/or sell copies of the Software, and to
09: * permit persons to whom the Software is furnished to do so, subject to
10: * the following conditions:
11: *
12: * The above copyright notice and this permission notice shall be
13: * included in all copies or substantial portions of the Software.
14: *
15: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21: * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22: */
23:
24: package org.keplerproject.luajava.test;
25:
26: import org.keplerproject.luajava.LuaObject;
27: import org.keplerproject.luajava.LuaState;
28: import org.keplerproject.luajava.LuaStateFactory;
29:
30: /**
31: * Tests LuaJava running as a multithreaded application.<br>
32: * The objective of the test is to see that LuaJava behaves
33: * properly when being executed from diferent threads.
34: *
35: * @author thiago
36: */
37: public class ThreadTest {
38: private static String lua = "function run() io.write('test\\n');"
39: + "io.stdout:flush();"
40: + "luajava.bindClass('java.lang.Thread'):sleep(100);"
41: + " end;tb={run=run}";
42:
43: public static void main(String[] args) throws Exception {
44: LuaState L = LuaStateFactory.newLuaState();
45: L.openBase();
46: L.openIo();
47: //L.openLibs();
48:
49: L.LdoString(lua);
50:
51: for (int i = 0; i < 100; i++) {
52: LuaObject obj = L.getLuaObject("tb");
53: Object runnable = obj.createProxy("java.lang.Runnable");
54: Thread thread = new Thread((Runnable) runnable);
55: thread.start();
56: }
57: System.out.println("end main");
58: }
59: }
|