模板方法

4.线程模板类

和BaseHandler相似的封装。

public abstract class NamedRunnable implements Runnable {  
   protected final String name;  
   public NamedRunnable(String format, Object... args) {  
   this.name = Util.format(format, args);  }  
   @Override 
   public final void run() {  
       String oldName = Thread.currentThread().getName();
       Thread.currentThread().setName(name);
 try {      
        execute();  
  } finally {  
       Thread.currentThread().setName(oldName); 
   }  
} 
 protected abstract void execute();
}

你可能感兴趣的:(模板方法)