亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

簡單代碼中的內存泄漏?在任何地方都找不到答案

簡單代碼中的內存泄漏?在任何地方都找不到答案

Helenr 2022-09-07 21:32:55
此代碼逐漸消耗內存,從大約130 MB開始(由于依賴性),并在我必須殺死它并重新啟動它(因為服務器內存不足)之前不斷爬升到800 + MB。它與OpenJDK 11一起運行。我有一個舊版本的代碼運行在Java 8服務器上,其內存使用率保持穩定并且永遠不會增加。所以我不確定它是否與新的JDK有關?我在這里修改了相當多的代碼,以確保它盡可能簡單 - 但仍然有問題?;疽c - 它是否每隔幾秒鐘查詢一次數據庫以查找待處理的發票。但是,沒有待處理的發票(日志也證明了這一點),因此它永遠不會進入復雜的代碼位置,而只會每隔幾秒鐘繼續重復一次。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 ; ";
查看完整描述

1 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

驅動程序可能會產生內存泄漏。我在 Unify SQL 數據庫上遇到了這個問題。將驅動程序更新到最新版本。

在postgres中看到這一點


查看完整回答
反對 回復 2022-09-07
  • 1 回答
  • 0 關注
  • 78 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號