Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java Interrupts

Name: Anonymous 2011-12-30 22:41

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: Anonymous 2012-01-01 4:14

>>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);
    }

    private static final Primitive GC = new gc();
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List