简单代码中的内存泄漏?在任何地方都找不到答案

此代码逐渐消耗内存,从大约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 ; ";

Helenr
浏览 58回答 1
1回答

回首忆惘然

驱动程序可能会产生内存泄漏。我在 Unify SQL 数据库上遇到了这个问题。将驱动程序更新到最新版本。在postgres中看到这一点
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java