I have created a Java application and there is a thread that is doing something in the background when pressing a button. The problem is that the thread may probably launch, maybe due to the infinite loop Is there any way that I can end that thread?
EDIT: I am using Lewaj on the Java platform. It has locking capability and I do not have much control over it except in another thread, and when Java or script ends it kills it.
No, no. Without the big magic doctrine, your only choice is to call on the conscience () and wait to kill the call blocking it. At that point, it will put a blocking exception that you should end the thread.
If it is in the loop like while (1);
You can not really do much; You do not have to fix your thread to do this, or check at least one flag and stop yourself. For example, you can rewrite:
while (1) {work (); } As
:
whatever the class (private volatile boolean stop = false; ... while ((stop!) {DoalittleWork ( );} ...}
There was a method that does this but it is disliked for very good reasons and should not be used.
Edit: Since you are potentially running an interpreter, after executing every statement you have the hook and check your magic stop
variable, and if Ai Alternatively, Lia execution Alternatively, the Leah Runtime can have its "End" flag which you can use - I looked for the documentation but their site is terrible, so you may have to look up the code for it.
In addition to this, you may have to manually patch the Lua4j source to add this feature. Your options are quite limited and ultimately the thread is in any way to control your destiny.
Comments
Post a Comment