java耗时任务有哪些,java web通过线程运行耗时任务

try {

// 过程结束

class MyThread extends Thread{

private Carinfo carinfo;

private Carresult carresult;

public MyThread() {

super();

}

public MyThread(Carinfo carinfo,

Carresult carresult) throws IllegalAccessException, InvocationTargetException {

super();

this.carinfo = new Carinfo();

BeanUtils.copyProperties(this.carinfo, carinfo);

this.carresult = new Carresult();

BeanUtils.copyProperties(this.carresult, carresult);

}

public void run(){

try {

//上传数据,放到线程中运行

StringUtil.uploadResult(getAjNetinfo(), carinfo, carresult,

getStation(), commonService);

} catch (Exception e) {

// TODO Auto-generated catch block

logger.error("检测结果数据上传和检测过程结束:" + ContextUtil.getTrace(e));

}

}

}

Thread thread = new MyThread(carinfo,carresult);

thread.start();

} catch (Exception e) {

// TODO: handle exception

logger.error("MyThread检测结果数据上传和检测过程结束:" + ContextUtil.getTrace(e));

}

commonService为Hiberante的数据库操作的服务类

getStation()从数据库读取站点信息。

BeanUtils工具类为commons-beanutils-1.9.2.jar

注意:本文归作者所有,未经作者允许,不得转载

你可能感兴趣的:(java耗时任务有哪些)