Stops all threads that were run via start Thread(). - Java java.lang

Java examples for java.lang:Thread

Description

Stops all threads that were run via start Thread().

Demo Code

/*//from   w ww  .j a  v a  2  s  .  c o  m
     * Copyright (c) 2014 mgamelabs
     * To see our full license terms, please visit https://github.com/mgamelabs/mengine/blob/master/LICENSE.md
     * All rights reserved.
     */
    //package com.java2s;
    import java.util.ArrayList;
    import java.util.List;

    public class Main {
        public static void main(String[] argv) throws Exception {
            stopAllThreads();
        }

        private static List<Thread> threads = new ArrayList<Thread>();

        /**
         * Stops all threads that were run via startThread().
         * Note that all mengine threads will be stopped as well.
         */
        public static void stopAllThreads() {
            threads.forEach(Thread::interrupt);
        }
    }

Related Tutorials