java程序员-http://www.it-ebooks.info/

年轻的我,脚踩大地,仰望天空,路还很长....

博客园 首页 新随笔 联系 订阅 管理
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();

 

posted on 2014-09-26 09:39  gstsyyb  阅读(179)  评论(0编辑  收藏  举报