此代码逐渐消耗内存,从大约130 MB开始(由于依赖性),并在我必须杀死它并重新启动它(因为服务器内存不足)之前不断爬升到800 + MB。它与OpenJDK 11一起运行。我有一个旧版本的代码运行在Java 8服务器上,其内存使用率保持稳定并且永远不会增加。所以我不确定它是否与新的JDK有关?我在这里修改了相当多的代码,以确保它尽可能简单 - 但仍然有问题。基本要点 - 它是否每隔几秒钟查询一次数据库以查找待处理的发票。但是,没有待处理的发票(日志也证明了这一点),因此它永远不会进入复杂的代码位置,而只会每隔几秒钟继续重复一次。public static void main(String[] args) { ... final int interval = Constants.INTERVAL; QuickBooksInvoices qbInvoices = new QuickBooksInvoices(filename); qbInvoices.testConnection(); log.log(Level.INFO, "Checking invoices with an interval of " + interval + " seconds..."); while (isRunning == true) { qbInvoices.process(); try { Thread.sleep(interval * 1000); } catch (InterruptedException e) { } }}public void process() { errorBuffer.clear(); // These are array lists successBuffer.clear(); // These are array lists try (Connection conn = DriverManager.getConnection(dbURI, dbUser, dbPassword)) { ArrayList<com.xxx.quickbooks.model.wdg.Invoice> a = getInvoices(conn); OAuthToken token = null; if (a.size() > 0) { // Never gets here - no results } for (com.xxx.quickbooks.model.wdg.Invoice invoice : a) { // Never gets here - no results } } catch (Exception e) { writeLog(Level.ERROR, ExceptionUtils.getStackTrace(e)); }}private ArrayList<com.xxx.quickbooks.model.wdg.Invoice> getInvoices(Connection conn) { ArrayList<com.xxx.quickbooks.model.wdg.Invoice> invoices = new ArrayList<com.xxx.quickbooks.model.wdg.Invoice>(); String sql = "select " + "id," + "type," + "status," + "business_partner_id," + "invoice_number," + "total," + "nrc," + "szrc," + "trans_ts," + "warehouse_id," + "due_date," + "ref_number," + "payment_type " + "FROM dv_invoice " + "WHERE exported_ts is NULL AND exported_msg is NULL ; ";
添加回答
举报
0/150
提交
取消