问题遇到的现象和发生背景
主进程到一个表去搜索需要执行的sql代码,启动一个线程,然后把需要执行的sql代码给新启动的线程去执行,执行完线程就自动退出,如果是20个以内的的线程,一般没有问题。当线程启动超过40个以上就开始报以上的错误了。
报错提示:
Exception in thread "Thread-4927" java.lang.OutOfMemoryError: Java heap space
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
at org.postgresql.jdbc.PgCallableStatement.executeWithFlags(PgCallableStatement.java:83)
at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
at com.Settle.exec_sql(Settle.java:553)
at com.mythread.run(mythread.java:26)
操作环境、软件版本等信息
Linux version 3.10.0-957.el7.x86_64
jdk 版本 java version "1.8.0_144"
尝试过的解决方法
线程数量减少到20个以下,很稳定