2016-12-14 376 views
0

我正在嘗試使用Apache POI讀取具有2G堆內存的簡單8 MB文件。 但我得到以下例外。獲取java.lang.OutOfMemoryError:讀取excel文件時超出了GC開銷限制

14:53:20,437 ERROR [stderr] (server-timer) java.lang.OutOfMemoryError: GC overhead limit exceeded 
14:53:20,438 ERROR [stderr] (server-timer)  at java.util.HashMap.newKeyIterator(HashMap.java:968) 
14:53:20,439 ERROR [stderr] (server-timer)  at java.util.HashMap$KeySet.iterator(HashMap.java:1002) 
14:53:20,439 ERROR [stderr] (server-timer)  at java.util.HashSet.iterator(HashSet.java:170) 
14:53:20,440 ERROR [stderr] (server-timer)  at java.util.Collections$SynchronizedCollection.iterator(Collections.java:1632) 
14:53:20,441 ERROR [stderr] (server-timer)  at org.jboss.sun.net.httpserver.ServerImpl$ServerTimerTask.run(ServerImpl.java:844) 
14:53:20,441 ERROR [stderr] (server-timer)  at java.util.TimerThread.mainLoop(Timer.java:555) 
14:53:20,442 ERROR [stderr] (server-timer)  at java.util.TimerThread.run(Timer.java:505) 
14:53:20,442 ERROR [stderr] (DataImportFeedEngine-1) java.lang.OutOfMemoryError: GC overhead limit exceeded 
14:53:20,443 ERROR [stderr] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) java.lang.OutOfMemoryError: GC overhead limit exceeded 
14:53:20,444 ERROR [stderr] (cluster-ClusterId{value='58510c2638359c3ff495fb11', description='null'}-localhost:27017) java.lang.OutOfMemoryError: GC overhead limit exceeded 
14:53:20,445 ERROR [stderr] (pool-3-thread-1) java.lang.OutOfMemoryError: GC overhead limit exceeded 
14:53:20,446 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.addConditionWaiter(AbstractQueuedSynchronizer.java:1857) 
14:53:20,447 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2073) 
14:53:20,448 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090) 
14:53:20,448 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807) 
14:53:20,449 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) 
14:53:20,452 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) 
14:53:20,453 ERROR [stderr] (pool-3-thread-1) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
14:53:20,453 ERROR [stderr] (pool-3-thread-1) at java.lang.Thread.run(Thread.java:745) 
14:53:20,454 ERROR [stderr] (pool-2-thread-1) java.lang.OutOfMemoryError: GC overhead limit exceeded 
14:53:20,455 ERROR [stderr] (pool-4-thread-1) java.lang.OutOfMemoryError: GC overhead limit exceeded 

下面是產生問題的代碼:

FileInputStream file = new FileInputStream(new File(srcFileName)); 
    XSSFWorkbook workbook = new XSSFWorkbook(file); 
    XSSFSheet sheet = workbook.getSheetAt(0); 

我不認爲這麼多內存需要這個手術,我知道有問這個多的問題,但我想很多東西?

+0

有關的.xlsx文件低內存讀取,請參考http://stackoverflow.com/questions/12513981/reading-data-from-xlsx-with-apache-pois-sxssfsheet – diufanman

+1

閱讀文檔並遵循http://poi.apache.org/spreadsheet/how-to.html#xssf_sax_api? – Gagravarr

回答

相關問題