Java Heap Memory error

后端 未结 6 1232
遇见更好的自我
遇见更好的自我 2021-01-06 05:40

I am getting this error:

Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space
    at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1585         


        
6条回答
  •  天命终不由人
    2021-01-06 06:12

    When you query returns very large sets, the mysql driver will by default load the entire result set in memory before giving you control back. It sounds like you're just running out of memory, so increase the memory furter, e.g. -Xmx1024M

    The other alternative might be to enable streaming results on your MySQL queries- this prevents the entire ResultSet to be loaded into memory all at once. This can be done by doing

    stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, 
               java.sql.ResultSet.CONCUR_READ_ONLY);//These are defaults though,I believe
    stmt.setFetchSize(Integer.MIN_VALUE);
    

    (Note that anything else but Integer.MIN_VALUE has no effect on the MySQL driver)

提交回复
热议问题