[仗贱天涯]Code-AbstractParseThread

package com.ty.parse; import com.ty.util.Logger; import java.text.SimpleDateFormat; public abstract class AbstractParseThread extends Thread { private final static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private boolean terminal = false; private boolean postStopTag=false; private Object parsed=null; protected ParseProcessListener ppl=null; public AbstractParseThread(){ } public AbstractParseThread(ParseProcessListener pl) { this.ppl=pl; } public void run() { Logger.log("Thread "+this+" start at "+sdf.format(new java.util.Date())+"..."); long t=System.currentTimeMillis(); try { if(ppl==null){ ppl=new ParseProcessAdapter(); } terminal=false; ppl.processStart(); parsed=parse(); } catch (ParseException ex) { Logger.log(ex.getMessage()); throw ex; } finally { terminal = true; ppl.processFinished(); } t=(System.currentTimeMillis()-t); if(t<1000){ Logger.log("Used "+t+" ms."); }else{ Logger.log("Used "+(t/1000)+"s."); } } public boolean isTerminal() { return terminal; } public void postStop(){ postStopTag=true; } public boolean isPostedStop(){ return postStopTag; } public Object getParsed(){ return parsed; } public abstract Object parse()throws ParseException; }

你可能感兴趣的:(thread,object,null,Class,import,Terminal)