public static class MyThread extends Thread { @Override public void run() { try { while(true){//此处模拟有源源不断的任务需要处理 service();//挂接业务逻辑点 } }catch(InterruptedException e) { System.out.println("检测到中断请求,正在处理中...."); }finally { System.out.println("中断处理完毕,释放所占的资源!!"); } } void service() throws InterruptedException { System.out.println("do working....."); Thread.currentThread().sleep(1000); } } MyThread t = new MyThread(); t.start(); Thread.currentThread().sleep(12000); System.out.println("请求web关闭服务!!"); t.interrupt();