This seems to be a limitation of LuaJ. I applied for a ticket earlier this year at Sourceforge, as I see you did too. The LuaThread class LuaThread not store references to the Java threads it creates, so you cannot interrupt() those threads without modifying the LuaJ core to expose them:
new Thread(this, "Coroutine-"+(++coroutine_count)).start();
It might be dangerous to interrupt these threads without adding the appropriate cleanup code to LuaJ.
The documentation you provided for OrphanedThread also tells us that the scope is defining:
"An error has been detected that indicates that the lua thread that is no longer referenced has been detected. The java thread to which it was selected must match LuaThread, which is used as a coroutine that cannot be resumed again because it is no longer refer to the LuaThread with which it is associated.Instead of blocking resources permanently, this error occurs and should completely go to the thread of the Thread.run () method.
Your sample code does not cause all LuaThread links to disappear, so you should not expect an exception to be thrown. CoroutineLib documentation indicates: Coroutines that are yielded but never resumed to complete their execution may not be collected by the garbage collector , so OutOfMemoryError should be expected from the code that you specified in SourceForge if I am not mistaken. LuaThread:52 also indicates: Applications should not catch OrphanedThread, because it can break the thread safety of luaj. , which is another obstacle.
There are also differences between the empty and non-empty while contours in Lua / J. IIRC, empty loops ( while true do end ) do not obey all tuple / ticket rules. * Since no action occurs in an empty loop, there is no possibility for certain interceptions (I need to check this again, so please correct me otherwise!).
The deployed version of LuaJ with the functionality we are looking for is used in the ComputerCraft module for Minecraft, although it is intended for mods only and is not open source.
source share