lets say I have the following code:
public void run()
{
executeExternalLibraryCall();
}
and this is inside a class that extends Thread and implements Runnable.
For now assume executeExternalLibraryCall() basically goes into an infinite loop.
Now this whole process is being ran in another Thread via thread.start()...
I wish to interrupt it so that it stops execution of the external library call and returns from run thus destroying the thread, i thought about using thread.interrupt() on it but from what i've read online it seems that only works if the method were to throw InterruptedException which my external library call does not and i can't check for isInterrupted() while doing the external library call since it basically is an infinite loop so once called i lose all control in that thread.
How do i interrupt it to exit from that infinite loop in the external library call and return from run()?
Name:
Anonymous2011-12-30 22:58
use int 0x80
Name:
Anonymous2011-12-30 23:00
You can't. If the method being called enters an infinite loop, all you can do is hope it exits or, if you have access to the library source, add a check for a 'running' variable and set it to false.
Name:
Anonymous2011-12-30 23:02
>>3
One would think with java's vast library they would have a means to interrupt a running method. Luckily i do have the source to the external library, i guess i'll go in and fool around with it.
Whenever I'm playing Minecraft, JAVA INTERRUPTS to run the garbage collector, and I get killed by some faggot who spends 10 hours tuning the GC settings on his JVM.
>>6
Implement the following code into your Minecraft and run it in a seperate thread. You may think calling the GC every 200 milliseconds is suicide but in reality the GC works best when there are minimum amounts of objects to be free'd versus when it has to free tons and tons of objects.
The normal GC is pure shit in java, it's known for waiting until the last second until it even decides to free old memory and thus you get these big spikes in cpu usage at key points in your program which lead to slowdowns.
package org.armedbear.lisp;
import static org.armedbear.lisp.Lisp.*;
// ### gc
public final class gc extends Primitive
{
private gc()
{
super("gc", PACKAGE_EXT);
}
@Override
public LispObject execute()
{
Runtime runtime = Runtime.getRuntime();
long free = 0;
long maxFree = 0;
while (true) {
try {
runtime.gc();
Thread.sleep(100);
runtime.runFinalization();
Thread.sleep(100);
runtime.gc();
Thread.sleep(100);
}
catch (InterruptedException e) {}
free = runtime.freeMemory();
if (free > maxFree)
maxFree = free;
else
break;
}
return number(free);
}