2015-05-28 74 views
1

在Windows機器上運行Appium Android測試腳本執行時,我們看到Java堆空間異常。我們使用Apache POI進行測試數據表閱讀。直到第11個腳本套件運行正常,從第12個腳本開始看到Java堆空間異常。java.lang.OutOfMemoryError:Java堆空間 - Appium - TestNG Suite

我在Eclipse中增加了系統環境變量和TestNG Run Configuration中的堆和預留空間enter code here。有時候沒有問題,有時會遇到Java堆空間異常。

隨着下面的消息我懷疑使用fileinputstream讀取測試數據表,基於其他論壇,它加載時需要更多的內存,雖然測試數據沒有大量的數據。我已經使用

代碼是:

File strExecutionConfigFile = new File(
      strImportedExecutionConfigFilePath); 

try { 
     strInputExecutionConfigFile = new FileInputStream(
       strExecutionConfigFile); 
    } catch (FileNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    try { 
     objExecutionConfigWKB = new XSSFWorkbook(
       strInputExecutionConfigFile); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

我看到XSSF讀者格式將消耗低內存。可以在此提供代碼。

您可以訪問以下鏈接,Java堆空間異常

https://app.box.com/s/9t3or72lk44liolz8x22n9s0pk2klrna

回答

0

您需要檢查堆轉儲。添加以下VM ARGS:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/some/location 

這將轉儲下面的內容在下一次像你OOME

java_pid27643.hprof 

然後使用jvisualvm加載堆轉儲。在Linux中的命令是:

$ jvisualvm & 

您將需要加載並檢查轉儲文件,並嘗試找出是什麼導致OOME。文檔here

相關問題