Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static final String SERVER_WORKER_NAME = ".*\\.HttpRequestHandler-\\d+"; public static int countServerWorkerThreads() { return countThreads(SERVER_WORKER_NAME); } private static int countThreads(String namePattern) { Thread[] list = new Thread[100]; Thread.enumerate(list); int matches = 0; for (Thread element : list) { if (element != null) { if (element.getName().matches(namePattern) || element.getClass().getName().matches(namePattern)) { matches++; } } } return matches; } }