欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java根据线程ID中断线程组中的某一个线程,java线程,/** * In

来源: javaer 分享于  点击 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;    }
相关栏目:

用户点评