terminate Application via Thread - Java java.lang

Java examples for java.lang:Thread

Description

terminate Application via Thread

Demo Code


//package com.java2s;
import java.util.Set;

public class Main {
    public static void main(String[] argv) throws Exception {
        terminateApplication();/*from   w  w w . ja va  2s  .  c o m*/
    }

    public static void terminateApplication() {
        Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
        Thread[] threads = threadSet.toArray(new Thread[threadSet.size()]);
        for (int i = 0; i < threads.length; i++) {
            if (!(threads[i].equals(Thread.currentThread()))) {
                threads[i].interrupt();
            }
        }
    }
}

Related Tutorials