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

Pages: 1-

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 2011-12-30 22:58

use int 0x80

Name: Anonymous 2011-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: Anonymous 2011-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.

Name: Anonymous 2011-12-30 23:33

>>1 >>4
be a man, Thread.stop()

Name: Anonymous 2012-01-01 3:27

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.

Name: Anonymous 2012-01-01 4:07

>>6
Can you actually notice that?

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

Name: Anonymous 2012-01-01 5:36

>>8
No, don't do that unless you know it's going to do a concurrent gc otherwise it's stop-the-world slowdown



JVM_ENTRY_NO_ENV(void, JVM_GC(void))
  JVMWrapper("JVM_GC");
  if (!DisableExplicitGC) {
    Universe::heap()->collect(GCCause::_java_lang_system_gc);
  }
JVM_END

void GenCollectedHeap::collect(GCCause::Cause cause) {
  if (should_do_concurrent_full_gc(cause)) {
#ifndef SERIALGC
    // mostly concurrent full collection
    collect_mostly_concurrent(cause);
#else  // SERIALGC
    ShouldNotReachHere();
#endif // SERIALGC
  } else {
#ifdef ASSERT
    if (cause == GCCause::_scavenge_alot) {
      // minor collection only
      collect(cause, 0);
    } else {
      // Stop-the-world full collection
      collect(cause, n_gens() - 1);
    }
#else
    // Stop-the-world full collection
    collect(cause, n_gens() - 1);
#endif
  }
}

bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
  return UseConcMarkSweepGC &&
         ((cause == GCCause::_gc_locker && GCLockerInvokesConcurrent) ||
          (cause == GCCause::_java_lang_system_gc && ExplicitGCInvokesConcurrent));
}

Name: Anonymous 2012-01-01 19:35

>>9
Someone needs to write a parody of "I'll stop the world and melt with you" about Java's GC.

Name: DUBS LIBERATION FRONT 2012-03-24 18:32

NON-DUBS SHALL BE CLEANSED FROM THE EARTH!

Name: Anonymous 2012-03-24 23:23

Insane.  I didn't think anyone on /prog/ had any knowledge of how Java's GC works and everyone was just going along with the "it sucks" mentality.

Name: Anonymous 2012-03-25 0:15

If its shit /prog/ university covers it.
1000.1 リスプ
1000.2 GC I
1000.3 GC II
1000.4 GC III
1000.5 Not Lisp

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