package com.dy.common.threadPool; 
 | 
  
 | 
  
 | 
public class Test { 
 | 
  
 | 
// 
 | 
//    public static void main(String args[])throws Exception { 
 | 
////        Test t = new Test(); 
 | 
////        t.testShort1(); 
 | 
////        t.testShort2(); 
 | 
////        t.testLong(); 
 | 
//    } 
 | 
  
 | 
    /** 
 | 
     * 测试增加线程线程   
 | 
     * @throws Exception  
 | 
     * 
 | 
     */ 
 | 
    @SuppressWarnings("unused") 
 | 
    private void testShort1() throws Exception { 
 | 
        TreadPoolFactory.initThreadPoolShort("测试线程组",    2, 1, 10, 20); 
 | 
        ThreadPool.Pool pool = TreadPoolFactory.getThreadPoolShort() ; 
 | 
        try { 
 | 
            int n = 1 ; 
 | 
            Thread.sleep(1000); 
 | 
            while (n < 4) { 
 | 
                System.out.println("加入短工作任务(" + n + ")"); 
 | 
                pool.putJob(new ThreadPool.Job() { 
 | 
                    public void execute() { 
 | 
                        System.out.println("!!!!!开始短工作" + this.hashCode()); 
 | 
                        try { 
 | 
                            Thread.sleep(2000); 
 | 
                        } catch (Exception e) { 
 | 
                            ; 
 | 
                        } 
 | 
                        System.out.println("!!!!!结束短工作" + this.hashCode()); 
 | 
                    } 
 | 
                    @Override 
 | 
                    public void destroy(){ 
 | 
                    } 
 | 
                    @Override 
 | 
                    public boolean isDestroy(){ 
 | 
                        return false ; 
 | 
                    } 
 | 
                }); 
 | 
                n++ ; 
 | 
                Thread.sleep(100); 
 | 
            } 
 | 
        } catch (Exception e) { 
 | 
  
 | 
        } 
 | 
    } 
 | 
    /** 
 | 
     * 测试增加线程线程   
 | 
     * @throws Exception  
 | 
     * 
 | 
     */ 
 | 
    @SuppressWarnings("unused") 
 | 
    private void testShort2() throws Exception { 
 | 
        TreadPoolFactory.initThreadPoolShort("测试短工作线程组", 2, 1, 5, 6); 
 | 
        ThreadPool.Pool pool = TreadPoolFactory.getThreadPoolShort() ; 
 | 
        try { 
 | 
            int n = 1 ; 
 | 
            Thread.sleep(1000); 
 | 
            while (n < 2) { 
 | 
                System.out.println("加入短工作任务(" + n + ")"); 
 | 
                pool.putJob(new ThreadPool.Job() { 
 | 
                    @Override 
 | 
                    public void execute() { 
 | 
                        Long times = 0L ; 
 | 
                        System.out.println("!!!!!开始短工作" + this.hashCode()); 
 | 
                        while(true){ 
 | 
                            if(this.isDestroy == null || !this.isDestroy.booleanValue()){ 
 | 
                                times++ ; 
 | 
                                System.out.println("!!!!!执行短工作" + this.hashCode() + " 次数:" + times); 
 | 
                                try { 
 | 
                                    Thread.sleep(2000); 
 | 
                                } catch (Exception e) { 
 | 
                                    ; 
 | 
                                } 
 | 
//                                System.out.println("!!!!!结束长工作" + this.hashCode()); 
 | 
                            } 
 | 
                        } 
 | 
                    } 
 | 
                    @Override 
 | 
                    public void destroy(){ 
 | 
                        this.isDestroy = true ; 
 | 
                    } 
 | 
                    @Override 
 | 
                    public boolean isDestroy(){ 
 | 
                        if(this.isDestroy == null){ 
 | 
                            return false ; 
 | 
                        } 
 | 
                        return this.isDestroy.booleanValue() ; 
 | 
                    } 
 | 
                    private Boolean isDestroy; 
 | 
                }); 
 | 
                n++ ; 
 | 
                Thread.sleep(100); 
 | 
            } 
 | 
        } catch (Exception e) { 
 | 
  
 | 
        } 
 | 
    }/** 
 | 
     * 测试增加线程线程   
 | 
     * @throws Exception  
 | 
     * 
 | 
     */ 
 | 
    @SuppressWarnings("unused") 
 | 
    private void testLong() throws Exception { 
 | 
        TreadPoolFactory.initThreadPoolLong("测试长工作线程组", -1, 1, 5, -1); 
 | 
        ThreadPool.Pool pool = TreadPoolFactory.getThreadPoolLong() ; 
 | 
        try { 
 | 
            int n = 1 ; 
 | 
            Thread.sleep(1000); 
 | 
            while (n < 2) { 
 | 
                System.out.println("加入长工作任务(" + n + ")"); 
 | 
                pool.putJob(new ThreadPool.Job() { 
 | 
                    @Override 
 | 
                    public void execute() { 
 | 
                        Long times = 0L ; 
 | 
                        System.out.println("!!!!!开始长工作" + this.hashCode()); 
 | 
                        while(true){ 
 | 
                            if(this.isDestroy == null || !this.isDestroy.booleanValue()){ 
 | 
                                times++ ; 
 | 
                                System.out.println("!!!!!执行长工作" + this.hashCode() + " 次数:" + times); 
 | 
                                try { 
 | 
                                    Thread.sleep(2000); 
 | 
                                } catch (Exception e) { 
 | 
                                    ; 
 | 
                                } 
 | 
//                                System.out.println("!!!!!结束长工作" + this.hashCode()); 
 | 
                            } 
 | 
                        } 
 | 
                    } 
 | 
                    @Override 
 | 
                    public void destroy(){ 
 | 
                        this.isDestroy = true ; 
 | 
                    } 
 | 
                    @Override 
 | 
                    public boolean isDestroy(){ 
 | 
                        if(this.isDestroy == null){ 
 | 
                            return false ; 
 | 
                        } 
 | 
                        return this.isDestroy.booleanValue() ; 
 | 
                    } 
 | 
                    private Boolean isDestroy; 
 | 
                }); 
 | 
                n++ ; 
 | 
                Thread.sleep(100); 
 | 
            } 
 | 
        } catch (Exception e) { 
 | 
  
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |