java调用python的时候简单点还好,但是只要是一复杂,就会进程阻塞,但是我已经换了调用进程池的方法,还是依然会在运行到某一时间段停止
public ReturnObject save_info(HttpServletRequest request, HttpServletResponse response) {
return template.execute(new TransactionCallback<ReturnObject>() {
@Override
public ReturnObject doInTransaction(TransactionStatus transactionStatus) {
try {
// 更新状态 分析中
String rid = request.getParameter("rowid");// 当前记录
String fileId = request.getParameter("fileId");// 找寻
Map<String, Object> obj = new HashMap<>();
obj.put("m_status", "X3D2XYCQ4");// 分析中
cadao.update("vs_micro_material", KoC.sa("id", rid), obj);
new Thread(()->{
// 另起线程
/*
* 计划执行第一步:执行视频分帧。为:1s/3fps 计划执行第二步:执行人脸对比,传输人脸的照片 计划第三步执行:执行人脸分析 第四步执行执行:入库操作
*/
Map<String, Object> appendix = cadao.load("vs_base_appendix", KoC.b("id", fileId));
String apath = MapUtils.getString(appendix, "path");
logger.info("apath=" + apath);
String filePath = resolver.resolve(apath);
filePath = filePath.replace(File.separator, "\\");
filePath = filePath.replace("\\", "/");
filePath = filePath.replace("/", "\\\\");
String path = resolver.resolve("");
path = path.replace("\\", "\\\\");
path = path.substring(0, path.length()-8) + "\\jython\\\\zhen\\\\" + fileId + "\\\\";
// 创建一个新的文件夹,来存放python分帧数的图片
File toragepath = new File(path);
// 尝试创建一个新目录
boolean value = toragepath.mkdirs();
// 运行python脚本
String exe = "python";
String command = "\\jython\\together.py";
String photoPath = resolver.resolve("")+"photos_of_people_in_Ku\\";
photoPath = photoPath.replace("/", "\\");
photoPath = photoPath.replace("\\", "\\\\");
System.out.println(filePath);
System.out.println(photoPath);
System.out.println(path);
String[] cmdArr = new String[] {exe, command, filePath,photoPath, path };
Process process;
try {
process = Runtime.getRuntime().exec(cmdArr);
InputStream is = process.getInputStream();
process.waitFor(60,TimeUnit.SECONDS);
Map<String, Object> data = new HashMap<>();
data.put("m_status", "X3D2XYCQ5");// 分析结束
cadao.update("vs_micro_material", KoC.sa("id", rid), data);
result(fileId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}).start();
return r(true, "保存成功!");
}catch (Exception e) {
transactionStatus.setRollbackOnly();
logger.error("新增失败", e);
return r(false, "失败!");
}
}
这个是打印日志出现的报错,说我的进程没有任务数NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 1 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.