Created
March 31, 2015 13:42
-
-
Save CodingFabian/aa74bdecf24e85622d32 to your computer and use it in GitHub Desktop.
Interrupt a known thread in a known thread group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ThreadGroup[] threadGroups; | |
int groupCount = 0; | |
do { | |
threadGroups = new ThreadGroup[threadGroup.activeGroupCount() * 2]; | |
groupCount = threadGroup.enumerate(threadGroups, false); | |
} while (groupCount > threadGroups.length); | |
for (int i = 0; i < threadGroups.length; i++) { | |
ThreadGroup group = threadGroups[i]; | |
if (group != null && THREADGROUP_NAME.equals(group.getName())) { | |
Thread[] threads; | |
int threadCount = 0; | |
do { | |
threads = new Thread[group.activeCount() * 2]; | |
threadCount = group.enumerate(threads, false); | |
} while (threadCount > threads.length); | |
for (int j = 0; j < threads.length; j++) { | |
Thread thread = threads[j]; | |
if (thread != null && THREAD_NAME.equals(thread.getName())) { | |
thread.interrupt(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you java 1.0 apis.