How do I kill a ThreadGroup?!?!?!?

I'm trying to build a very simple Multiprocess JVM class manager. I can start my processes (classes with main) but I am trying to catch the System.exit method calls with a SecurityManager. I'm getting the following error when I try to kill a ThreadGroup
AWT blocker activation interrupted:
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:425)
at sun.awt.AWTAutoShutdown.activateBlockerThread(AWTAutoShutdown.java:312)
at sun.awt.AWTAutoShutdown.setToolkitBusy(AWTAutoShutdown.java:229)
at sun.awt.AWTAutoShutdown.notifyToolkitThreadBusy(AWTAutoShutdown.java:121)
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(WToolkit.java:222)
at java.lang.Thread.run(Thread.java:539)
The app I'm testing with is a simple Swing app with a JMenu. Listed below is the code I'm using as my sample Multiprocess manager.
// File Name: Sample2.java
import java.lang.reflect.*;
import java.awt.*;
import java.io.*;
import java.lang.Thread;
import java.util.*;
// very simple class to run code
public class Sample2 {
public static void main(String argv[]) {
ProcessMgr p = new ProcessMgr();
p.Run(argv);
// The security manager that will catch the System.exit calls
class ExitCatchingSecurityManager extends SecurityManager {
public void checkExit(int status) {
ThreadGroup tg = getThreadGroup();
Process.terminateProcessWithThreadGroup( tg );
System.out.println("Stopping ThreadGroup");
// this is the stmt that gets the error
tg.stop();
System.out.println("ThreadGroup stopped");
throw new SecurityException();
// The class that actually handles the Process Initiation and Termination
class Process implements Runnable {
String theClassName;
String[] theStartupArguments;
ThreadGroup mainThreadGroup;
Thread thisThread;
static ArrayList allProcesses = new ArrayList();
// terminate all processes associated with a particular ThreadGroup
public static void terminateProcessWithThreadGroup( ThreadGroup tg ) {
for (Iterator i = allProcesses.iterator() ; i.hasNext() ;) {
Process p = (Process) i.next();
if (p.getThreadGroup() == tg) {
System.out.println( "Terminating Thread" );
p.getThread().stop();
// pull out the ThreadGroup for this process
public ThreadGroup getThreadGroup() {
return mainThreadGroup;
// pull out the Thread for this process
public Thread getThread() {
return thisThread;
// Constructor
public Process( String classname, String[] args ) {
theClassName = classname;
theStartupArguments = args;
// Implement the run
public void run() {
try {
thisThread = Thread.currentThread();
mainThreadGroup = Thread.currentThread().getThreadGroup();
startAnotherClass( theClassName, theStartupArguments );
allProcesses.add( (Process) this );
} catch (Exception e) {
System.out.println("Could not start " + theClassName);
System.out.println(e);
// terminate this thread
public void terminate() {
if (thisThread != null)
thisThread.stop();
// Start a process in its own thread
public static Process startAnotherClassInItsOwnThread(String classname, String[] args) {
Process process = new Process( classname, args );
ThreadGroup threadgroup = new ThreadGroup("MPJVM");
Thread thread = new Thread( threadgroup, process );
thread.start();
return process;
// Here is the nuts and bolts of starting the class
public static void startAnotherClass( String className, String[] args ) throws Exception
// Get the class
Class classObject = Class.forName( className );
// Find the main(String[]) method of that class.
// main has one parameter, a string array. Set
// that argument type
Class[] mainParamType = { args.getClass() };
// Search for the main(String[]) method
Method main = classObject.getMethod("main", mainParamType);
// Create an object array of the arguments to pass
// to the method
Object[] mainParams = { args };
// start the real class
main.invoke( null, mainParams );
// The testing Application
class ProcessMgr {
public static void Run(String[] args) {
String s = "";
// Install the new Security Manager
System.setSecurityManager( new ExitCatchingSecurityManager( ) );
BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
System.out.println("Enter class to run or exit to terminate");
try {
while ( s.compareTo("exit") != 0) {
s = in.readLine();
if ( s.compareTo("exit") != 0 ) {
Process.startAnotherClassInItsOwnThread( s, args );
System.out.println("Process Started");
System.out.println("Enter next class or exit to terminate");
} catch (Exception eRead) {
System.out.println("Error reading string");
System.out.println( eRead );
System.exit(-1);

Thats OK if you are the author of the app you are running or the app you are running is designed so that you can modify it to do so. However, if you do not have that option, is there not another way?

Similar Messages

  • I mistakenly asked iTunes to download a TV series and I can't get it to stop trying to download it.   how do I kill the download?

    I mistakenly asked iTunes to download a TV series and I can't get it to stop trying to download it.   how do I kill the download?

    You've got to be freakin' kidding me. I'm in Brazil, I accidentally started a 2.2GB download that it says will take 592 minutes to download, and there's no way I can stop it and download something else until that first download finishes? I would have thought it was unthinkable 15 years ago that anyone would build an app that downloads things but doesn't allow the option of canceling the download, but in this day and age? So much for Apple making intuitive, user-friendly products.

  • I DON'T WANT TO UPGRADE OR HAVE AN ADD ON EVER, DISABLING UPDATES DOES NOT WORK, HOW DO I KILL ALL MEASAGES FOR UP GRADES AND ADD ON'S FOR EVER, ONCE AND FOR ALL, COMPLETELY, THE END AND NEVER BE BOTHERED AGAIN EVER!

    I DON'T WANT TO UPGRADE OR HAVE AN ADD ON EVER, DISABLING UPDATES DOES NOT WORK, HOW DO I KILL ALL MESSAGES FOR UP GRADES AND ADD ON'S FOR EVER, ONCE AND FOR ALL, COMPLETELY, THE END AND NEVER BE BOTHERED AGAIN EVER! ALSO IF I KILL MYSELF I WILL HOLD YOU PERSONALTY RESPONSIBLE.edit

    There is a world of information in these forums if you use the search function near the top right of this page. Just type in NAS for example and you get many threads on the subject (marked with a green checkmark if it solved the question) another example would be Airport Exterme and sound system. Once you formulate your ideas better then specific questions can be addressed one at a time. You may find that a less expensive choice for a server might be a mac mini. Good luck with your project, ask more specific questions and update you systems profile.

  • I click a link but it doesn't open. Instead I get a popup saying "Open the link in a new window," "Open link in a new tab," etc. How can I kill this popup or whatever it is forever?

    I click a link but it doesn’t open. Instead I get a popup saying “Open the link in a new window,” “Open link in a new tab,” etc. How can I kill this popup or whatever it is forever?

    That happens if the server sends the file as text/plain.
    You can see this if you open "Tools > Page Info > General": Content-Type: text/plain
    Files send this way will always open in a tab.
    *https://developer.mozilla.org/Tools/Web_Console

  • How can i kill the Adobe Reader session right away?

    Hello
    I have developed an interactive form, my_form. And we launch / render this my_form in (ERP / SAP) application's portal IE browser, well.
    Say, user opened this form, worked on it, submitted (we have our own submit button) and closed the window by clicking the top right corner's X button, but user is seeing stll the red Reader icon on the bottom bar, even thought the user is closed the window completely
    If user try to close this reader red reader icon explicitly, user is getting the other exception popup as Runtime error as described here http://forums.adobe.com/thread/391738
    Hence, am thinking to KILL the reader session right away the moment user closes the window, pls. let me know,
    1) How can i KILL the reader session via JavaScript, is it possible?
    2) if so, what the JS code i need to put and
    3) in which event pls.?
    Thank you

    In to my original posting, am attaching these pics
    On my desktop it looks like below,
    1) Even though user is closing the window but still the reader icon is lying on the bottom
    2) Once user double cliks the above red icon, user is getting below popup
    Thank you

  • Hi guys, the MUSIC app on my 2 iPad IOS 5 starts up playing music on its own very often. Any idea how I can kill the b....rd???

    Hi Guys, Apple's MUSIC app on my iPad 2 iOS 5 starts up playing music on its own frequently, I have to stop it evy time. Any idea how I can kill the b....d?? Thank you!

    Make sure that you have quit the app when you finish using it. To do so press the Home button once to return to the Home screen. Then press the Home button twice to reveal the open apps under the Dock. Tap and hold the Music app until it begins to jiggle and a appears in the upper left corner of the icon. Tap the to quit the app. Tap the screen or press the Home button to return the Dock to it original position.

  • How can i kill a job in BW

    Hi,
    Any budy please help me that how can i kill a background job in BW
    Cheers,
    KGB

    hi u can kill job in SM 37 also.
    also u can cancel in SM50.also use tis link
    How to stop scheduled job in bw.
    Hope it solves your query
    Thanks,
    pathak
    Edited by: npathak on Aug 2, 2010 9:09 PM

  • HT201365 On this new ios7 update how do I kill apps running in the background now? I used to be able to double tap the home button

    On this new ios7 update how do I kill apps running in the background now? I used to be able to double tap the home button

    Double tap the home button.  Slide the preview window upward.  You can do 2 at a time.
    It's rarely useful or necessary to do this. Very few apps actually "run in the background" (such as audio streaming and navigation apps).  The vast majority are frozen and consume no resources.  The iOS manages memory for you to optimize running apps.
    iOS: Understanding multitasking
    Message was edited by: modular747

  • How to drop/kill/end a MeetMe conference

    Hi,
    We have an issue that a MeetMe conference call has been opened and apparently has not been closed by one last participant.
    Unfortunately we do not know who it is and the participant also apparently is not aware that the line is still open. So how do we kill it?
    I've googled and searched the support community and came to the conclusion that it's not possible to kill it like you could kill it in an adhoc conference. There's a whole lot of links and docs and situations that are being referred too but no where a simple answer as to what I can do to kill this MeetMe session. So, what can I do?  Do I need to reboot the callmanager cluster, or can I kill it by disabling/enabling a service, or maybe deleting the MeetMe number and creating it again? Anyone has a simple answer?
    A second les important question I have is, is there a way to see who the active/current participants are in a MeetMe?
    Thanks in advance
    Regards,

    Restart the IPVMS, and no, the list functionality for conferences only works with ad-hoc
    HTH
    java
    if this helps, please rate
    www.cisco.com/go/pdihelpdesk

  • How can I kill database connections

    I would like to know how can I kill all the database connexion at the end of an application. I'm using acces
    thx

    use con.close() in a finally statement after your catch blocks that tests whether con equals null. If con != null, then con.close();
    example:
    finally {
              //close the database connection.
              try {
                      if (con != null) con.close();
              catch (SQLException e) {
    }

  • APEX_PLSQL_JOB: How to end/kill jobs

    Hi,
    I'm wondering if there's a good way to kill jobs that were created using APEX_PLSQL_JOB.
    I have a situation where I create a job using APEX_PLSQL_JOB. The process that it is executing will take a long time to run. After a while I decide that I need to end this job since it's slowing down the server. How can I terminate it?
    I've tried the following:
    - Kill the Oracle session that is executing the code. This terminated the process but just restarted it again a few seconds later
    - Purge the process using APEX_PLSQL_JOB.PURGE_PROCESS. This removed it from the list of APEX PL_SQL jobs in the APEX_PLSQL_JOBS view. It had no effect on the processing of the job.
    Any other ideas on how I can kill the process that I started?
    Thank you,
    Martin
    [http://apex-smb.blogspot.com/]

    On a related note, this is yet another great example of when to use the database resource manager. You could:
    - create a resource consumer group called "LONG_RUNNING_STUFF"
    - that group gets dropped to say 5% CPU after 5 min (just as an example)
    - any session in that group that has an operation that lasts longer than 20 minutes automatically killed (just as an example)
    - in your job code, make a call to DBMS_SESSION.SWITCH_CURRENT_CONSUMER_GROUP() to have that session put itself into the LONG_RUNNING_STUFF group (you need to assign a priv for this)
    It's a great way to let the db manage itself so you don't have to monitor sessions. You might also consider instrumenting your code with dbms_application_info.set_session_longops()
    Tyler Muth
    http://tylermuth.wordpress.com
    [Applied Oracle Security: Developing Secure Database and Middleware Environments|http://sn.im/aos.book]

  • I have a series of lost I bought that keeps trying to download, i don't want them how do I kill them?

    I bought lost series a year ago, I've watched and I don't plan on re-watching. itunes keeps trying to DL. How do I kill them off,, so they never, ever return to torment me again?

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes forums.
    Regards.

  • N97 Mini: How do I kill the annoying startup melod...

    Like the title says: How do I kill the annoying startup melody?
    Since this is my work phone, I might need to turn it off at meetings, but often turn it on during these to find a contact. And to have the blasted device draw unwanted attention with the annoying startup melody is not my idea of professionalism.
    Anyone know how to kill that melody? I can't seem to find any settings to turn it off, not does it look like any customization of the themes can affect this.

    Instead of turning it off for a meeting why not just select the offline profile? No one can contact you and it's much better for your battery life too.
    The start up animation can't be disabled but the following options may stop the sound:
    1. Press any key as the animation appears to skip it.
    2. Set the phone to the silent profile before you switch it off.
    3. In your current profile edit it to disable the warning tones. This may disable the sound but also some other system sounds too.

  • I lost my iPhone. how can I kill it?

    I lost my iPhone 4s at airport in oversea.
    Unfortunately, I could not find that.
    When I get back to US, I just bought one and recovered my contact and app etc on my new iPhone.
    But, I don't want somebody use my old iPhone for them.
    How can I kill it? As I heard that IPhone 4s has that kind of function that killed all the pictures & data deleted as first initial time.
    Just let me know. I know my IMEI number and etc.

    It was not activated.

  • How do you kill apps not in use?

    How do i kill apps not in use?

    Double-tap the home button and then swipe UP on the app preview window...not the app icon but the preview window above the icon.

Maybe you are looking for

  • Missing themes and titles in Premiere Elements 4

    I have recently downloaded a full version of this product and registered it. When I went through the tutorial to learn how to use it when I came to the adding titles and themes sections it would appear all the drop downs are empty. The effects and tr

  • Displaying an Integer in a JSP page

    Hi, i have a small problem which i'm not sure how to solve. I'm developing a small application in Spring/Hibernate. Now, one of the classes i mapped to a table has some fields which are of Integer type. My problem is that when i try to display these

  • Create single .folio file for desktop viewing

    Hi, I need a bit of help here please. We are currently on issue 2 of our iPad magazine: https://itunes.apple.com/gb/app/absolute-photo-magazine/id719597521?mt=8 We are trying to create a version of our app that Advertisers can view on all platforms (

  • Will be International for 5 months and want to remove plan for this time

    I will be studying in Austria for an extended period of time and would like to bring my iphone5, but not use any sort of plan with it (I'll just use wifi and as a camera). Right now I have a contract for several years (unlimited talk, text, and 2GB d

  • 2003 Server - Custom Support

    Does anyone know how to obtain Custom Support from Microsoft on Windows 2003, SP-2 servers, after EOS (7-14-15)?  I have a few 2003 servers that I think will cost too much to migrate to another OS, but I need to get Microsoft Custom Support costs to