public HttpQueueOperator(String fileStoreDir, String server) { this.fileStoreDir = new File(fileStoreDir); if (!this.fileStoreDir.exists() || !this.fileStoreDir.isDirectory()) { if (!this.fileStoreDir.mkdir()) { throw new RuntimeException("本地存储目录创建失败:" + this.fileStoreDir.getAbsolutePath()); } } if (StringUtils.isBlank(server)) { client = null; serverHost = null; logger.warn("没有指定服务器IP地址"); } else { serverHost = HttpHost.create("http://" + server); client = HttpIns.global(); File[] files = this.fileStoreDir.listFiles(file -> file.isFile() && file.getName().endsWith(".txt")); if (null != files) { Collections.addAll(fileBlockingQueue, files); } Thread taskSendThread = new Thread( () -> { while (true) { try { File file = fileBlockingQueue.take(); List<String> content; try { content = FileUtils.readLines(file, "utf-8"); } catch (IOException e) { logger.error("Http请求文件读取异常", e); fileBlockingQueue.offer(file); continue; } if (content.isEmpty()) { FileUtils.deleteQuietly(file); continue; } HttpRsp rsp; if (content.size() > 1) { rsp = _send(content.get(0), content.get(1)); } else { rsp = _send(content.get(0), null); } if (rsp.status != 200) { fileBlockingQueue.offer(file); try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException ignore) { } } else { FileUtils.deleteQuietly(file); } } catch (InterruptedException e) { logger.error("Http线程异常!!", e); } } }); taskSendThread.setName("HttpTaskSendThread-" + fileStoreDir); taskSendThread.start(); } }