// 此线程类必须实现 Runnable 接口 public class XmzNoticeErrorThread implements Runnable { private ICertImportErrorRecService iErrorRecService = ContainerFactory.getContainInfo() .getComponent(ICertImportErrorRecService.class); private int rowNum; private String errorTip; private String importrecGuid; private String operateusername; // 有参构造 XmzNoticeErrorThread(int rowNum, String errorTip, String importrecGuid, String operateusername) { this.rowNum = rowNum; this.errorTip = errorTip; this.importrecGuid = importrecGuid; this.operateusername = operateusername; } @Override public void run() { Log.info("导入importrecGuid的数据" + importrecGuid + "的数据第:" + rowNum + "条,有错误!"); // 声明锁 synchronized (XmzNoticeErrorThread.class) { handleFailedRec(rowNum, errorTip, importrecGuid, operateusername); } } // 处理逻辑 private void handleFailedRec(int rowNum, String errorTip, String importrecGuid, String operateusername) { 。。。。你想要实现的东西 } }
public void handleFailedRec(int rowNum, String errorTip, String importrecGuid) { XmzNoticeErrorThread xmzNoticeErrorThread = new XmzNoticeErrorThread(rowNum, errorTip, importrecGuid, userSession.getDisplayName()); new Thread(xmzNoticeErrorThread).start(); }