java根据线程ID中断线程组中的某一个线程,java线程,/** * In
分享于 点击 13230 次 点评:78
java根据线程ID中断线程组中的某一个线程,java线程,/** * In
/** * Interrupt the <code>Thread</code> using it thread id */ public synchronized boolean interruptThread(long threadID){ ThreadGroup threadGroup = workerThreads[0].getThreadGroup(); Thread[] threads = new Thread[threadGroup.activeCount()]; threadGroup.enumerate(threads); for (Thread thread: threads){ if ( thread != null && thread.getId() == threadID ){ if ( Thread.State.RUNNABLE != thread.getState()){ try{ thread.interrupt(); return true; } catch (Throwable t){ ; // Swallow any exceptions. } } } } return false; }
用户点评