--在方法内部启动线程
for(List<TaskInstanceBean> o : oList) {
BatchCheckThread t = new BatchCheckThread();
t.setComment(comment);
t.setStrDN(strDN);
t.setTibs(o);
t.setUser(this.getCurrentUser(request));
t.setCountDown(end);
new Thread(t).start();
}
BatchCheckThread 是一个内部类,然后在里面添加线程的代码
--跟踪哪个线程的里面执行的情况
Logger.getLogger(BatchCheckThread.class).info("开始执行线程:" + Thread.currentThread().getName() + ",条数:" + tibs.size());
--内部类里面执行线程
class BatchCheckThread implements Runnable {
private String comment;
private List<TaskInstanceBean> tibs;
private User user;
private String strDN;
private CountDownLatch countDown = null;
public void setCountDown(CountDownLatch countDown) {
this.countDown = countDown;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public List<TaskInstanceBean> getTibs() {
return tibs;
}
public void setTibs(List<TaskInstanceBean> tibs) {
this.tibs = tibs;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getStrDN() {
return strDN;
}
public void setStrDN(String strDN) {
this.strDN = strDN;
}
@Override
public void run() {
try {
long begin = System.currentTimeMillis();
Logger.getLogger(BatchCheckThread.class).info("开始执行线程:" + Thread.currentThread().getName() + ",条数:" + tibs.size());
execute();
Logger.getLogger(BatchCheckThread.class).info("线程:" + Thread.currentThread().getName() + ",耗时:" + (System.currentTimeMillis() - begin) + " ms");
} catch(Exception e) {
new RuntimeException(e);
} finally {
if(null != countDown) countDown.countDown();
}
}
private void execute() {
if(null == tibs) return;
for(TaskInstanceBean tib : tibs) {
List<Transition> trans = tib.getAvailableTransitions();
for(Transition tran : trans){
String tansName = tran.getName();
if(isCanApproval(comment, tib, tran)){
ServiceFactory.getInstance().getJbpmProcessService().handelTask(tib.getTaskInstanceId(), tansName, user, "批量"+tansName, strDN ,null);
break;
}
}
}
}
private boolean isCanApproval(String comment, TaskInstanceBean tib, Transition tran) {
if(tib.getTaskInstance().getName().equals("复核") && "同意".equals(comment)) {
return "送审批".equals(tran.getName());
}
return tran.getName().equals(comment + tib.getTaskInstance().getName());
}
}