| | |
| | | //默认线程大小 |
| | | private static final int DEFAULT_EXPORT_POOL = 4; |
| | | |
| | | private boolean isRun = false; |
| | | |
| | | public ExportDataExecutor(boolean isRun) { |
| | | |
| | | this.isRun = isRun; |
| | | } |
| | | |
| | | public ExportDataExecutor() { |
| | | this.userDownloadFileV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("userDownloadFileV1InnerServiceSMOImpl", IUserDownloadFileV1InnerServiceSMO.class); |
| | | this.fileUploadTemplate = ApplicationContextFactory.getBean("fileUploadTemplate", FileUploadTemplate.class); |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | |
| | | try { |
| | | doExportData(); |
| | | } catch (Exception e) { |
| | | log.error("处理消息异常", e); |
| | | e.printStackTrace(); |
| | | while (isRun) { |
| | | log.debug("导出数据线程开始处理"); |
| | | try { |
| | | doExportData(); |
| | | } catch (Throwable e) { |
| | | log.error("处理消息异常", e); |
| | | e.printStackTrace(); |
| | | } |
| | | log.debug("导出数据线程处理完成"); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | private void doExportData() throws Exception { |
| | | |
| | | ExportDataDto exportDataDto = ExportDataQueue.getData(); |
| | | |
| | | this.userDownloadFileV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("userDownloadFileV1InnerServiceSMOImpl", IUserDownloadFileV1InnerServiceSMO.class); |
| | | this.fileUploadTemplate = ApplicationContextFactory.getBean("fileUploadTemplate", FileUploadTemplate.class); |
| | | |
| | | ByteArrayInputStream inputStream = null; |
| | | ByteArrayOutputStream os = null; |
| | |
| | | inputStream = new ByteArrayInputStream(os.toByteArray()); |
| | | |
| | | fileName = fileUploadTemplate.saveFile(inputStream, exportDataDto.getFileName()); |
| | | |
| | | |
| | | updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FINISH,fileName, "下载完成"); |
| | | |
| | | } catch (Exception e) { |
| | | } catch (Throwable e) { |
| | | e.printStackTrace(); |
| | | updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FAIL, "","下载失败" + ExceptionUtil.getStackTrace(e)); |
| | | } finally { |
| | | try { |
| | |
| | | */ |
| | | public static void startExportDataExecutor() { |
| | | ExecutorService executorService = Executors.newFixedThreadPool(DEFAULT_EXPORT_POOL); |
| | | executorService.execute(new ExportDataExecutor()); |
| | | executorService.execute(new ExportDataExecutor(true)); |
| | | } |
| | | } |