Thread ID로 thread 찾기 (get thread by id)
뿌리튼튼 CS/Java2015. 7. 27. 17:23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ThreadGroup rootGroup = Thread.currentThread().getThreadGroup(); ThreadGroup parentGroup; while ((parentGroup = rootGroup.getParent()) != null) { rootGroup = parentGroup; } Thread[] threads = new Thread[rootGroup.activeCount()]; while (rootGroup.enumerate(threads, true) == threads.length) { threads = new Thread[threads.length * 2]; } for (Thread t : threads) { if (t.getId() == targetID) { /* found it */ } } | cs |
출처 :
'뿌리튼튼 CS > Java' 카테고리의 다른 글
생성자를 쓰는 이유. 생성자의 필요성 (Why use constructors) (0) | 2016.08.02 |
---|---|
심심풀이 문제1 - Object.equals() (0) | 2016.07.16 |
[Collection] ArrayList vs Vector (0) | 2016.02.01 |
String vs StringBuilder vs StringBuffer (2) | 2016.01.28 |
Array size in Loops (0) | 2015.07.31 |