存到数据库过程前,最好用临时文件保存一下,然后再读取文件存到数据库。正常情况,前台提交到后台,修改配置文件的上传大小,最主要耗时间的是文件处理,这个处理过程最好用线程做。
public ActionForward doFileAddExcute(ActionMapping mapping,
CommonForm form, HttpServletRequest request,
HttpServletResponse response) {
FileWorker worker = null;
// 処理No(0:処理中、1:成功、2:失敗)
String workNo = actionForm.getWorkNo();
//前台得到线程处理号
if (StringUtils.hasText(workNo)) {
worker = FileThreadPool.getWorker(workNo);
// 処理成功
if ("1".equals(worker.isFinish())) {
FileThreadPool.removeWorker(workNo);
} else if ("2".equals(worker.isFinish())) {
throw new SystemException();
}
} else {
//上传处理类
FileAddUpd fileAddUpdter = new FileRegist(fileVo, fileList);
worker = FileThreadPool.createrWorker(fileAddUpdter);
worker.start();
}
try {
// 根据得到文件
FileInfo fileInfoD = (FileInfo) fileList.get(0);
String fileSizeD = BusinessUtils.getTotalSize(
fileInfoD.getFileSize(), 0);
FileInfo fileInfoS = (FileInfo) fileList.get(1);
String fileSizeS = BusinessUtils.getTotalSize(
fileInfoS.getFileSize(), 0);
int fileSize = Integer.parseInt(fileSizeD)
+ Integer.parseInt(fileSizeS);
//根据文件大小估计处理的时间
if (fileSize < 5) {
Thread.sleep(5000);
} else if (fileSize < 50) {
Thread.sleep(30000);
} else {
Thread.sleep(60000);
}
} catch (InterruptedException e) {
throw new SystemException();
}
// 前台付処理No,以便下一次得到线程
actionForm.setWorkNo(worker.getThreadNo());
// request保存
request.setAttribute(Constants.FILETREAT_ACTIONFORM, actionForm);
// 処理中
if ("0".equals(worker.isFinish())) {
// 処理失敗
} else if ("2".equals(worker.isFinish())) {
throw new SystemException();
// 処理成功
} else {
FileThreadPool.removeWorker(workNo);
}
}
}