Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Wait for thread whose name contain the specified string to finish, i.e. to not appear in the
     * list of running threads any more.
     *
     * @param name
     *
     * @throws InterruptedException
     * @author dominik.stadler
     */
    public static void waitForThreadToFinishSubstring(final String name) throws InterruptedException {
        int count = Thread.currentThread().getThreadGroup().activeCount();

        Thread[] threads = new Thread[count];
        Thread.currentThread().getThreadGroup().enumerate(threads);

        for (Thread t : threads) {
            if (t != null && t.getName().contains(name)) {
                t.join();
            }
        }
    }
}