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

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