Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static Thread findThreadByName(String name) {
        ThreadGroup group = Thread.currentThread().getThreadGroup();

        while (group.getParent() != null)
            group = group.getParent();
        Thread[] threadList = new Thread[group.activeCount() + 5];
        group.enumerate(threadList, true);
        for (Thread thread : threadList)
            if (thread != null && thread.getName().equals(name))
                return thread;
        return null;
    }
}