2014-01-23 38 views

回答

1

調查的源代碼之後,我們發現,調用WritableWorkbook.close()時,默認行爲調用System.gc()的每一次!

void close(boolean cs) throws IOException, JxlWriteException { 
    CompoundFile cf = new CompoundFile(data, 
            data.getPosition(), 
            outputStream, 
            readCompoundFile); 
    cf.write(); 

    outputStream.flush(); 
    data.close(); 

    if (cs) { 
     outputStream.close(); 
    } 

    // Cleanup the memory a bit 
    data = null; 

    if (!workbookSettings.getGCDisabled()) { 
     System.gc(); 
    } 
} 

有兩種方法可以通過系統屬性

  • jxl.nogc=true避免這種情況,JXL的禁用GC(添加-Djxl.nogc=true到JVM參數)
  • XX:+DisableExplicitGC,禁用所有明確的GC(這是理想的下大多數情況下)。
0
WorkbookSettings workbookSettings = new WorkbookSettings(); 
     workbookSettings.setGCDisabled(true); 
     readwb = Workbook.getWorkbook(file.getInputStream(), workbookSettings); 
+0

你能詳細說明一下這段代碼在做什麼嗎?雖然它可能(或可能不)解決問題,但目前它並未顯示如何或爲何。 – Holloway

相關問題