SQL Server JDBC:无法创建新的本地线程 [英] SQL Server JDBC: unable to create new native thread

查看:160
本文介绍了SQL Server JDBC:无法创建新的本地线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Windows下使用Microsoft的sqljdbc驱动程序1.2与Hibernate结合使用。偶尔我们会从JDBC驱动程序中获取OutOfMemoryError,尽管JVM堆中仍有大量内存可用。
下面是我们得到的异常的堆栈跟踪:

  java.lang.OutOfMemoryError:无法创建新的本机在java.lang.Thread.start0处使用
(本地方法)$ b $在java.lang.Thread.start(Thread.java:597)
在com.microsoft.sqlserver.jdbc.TimeoutTimer 。开始(来源不明)
在com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(来源不明)
在com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(来源不明)
在com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement $ PrepStmtExecCmd.doExecute(来源不明)
在com.microsoft.sqlserver.jdbc.TDSCommand.execute(来源不明)
在com.microsoft.sqlserver.jdbc .SQLServerConnection.executeCommand(来源不明)
在com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(来源不明)
在com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(来源不明)
在com在com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery .microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(来源不明)
(NewProxyPreparedStatement.java:76)
。在org.hibernate.jdbc。 AbstractBatcher.getResultSet(AbstractBatcher.java:208)
org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections 697)
(Loader.java:259)
在org.hibernate.loader.Loader.doList(Loader.java:2228)
。在组织.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
在org.hibernate.loader.Loader.list(Loader.java:2120)
在org.hibernate.loader.criteria.CriteriaLoader .list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306 )

有没有可能t sqljdbc泄漏本机线程?

解决方案

根据这个线程,在语句中使用 setQueryTimeout 使得 executeQuery 为每个查询打开一个线程。这可能会导致驱动程序使用大量线程,并导致内存问题。不确定是否属于这种情况,无论如何不确定它是否在您的控制之下。实际上,您可能必须减少线程堆栈大小以避免此问题。 尝试将 -Xss128k 添加到您的JVM设置中。



请参阅这个线程这一个了解更多关于线程堆栈大小的信息和硬件限制。

We are using Microsoft's sqljdbc driver 1.2 in combination with Hibernate under Windows. Occasionally we are getting an OutOfMemoryError from the JDBC driver although plenty of memory is still available in the JVM heap. Here's a stack trace of the exception we are getting:

java.lang.OutOfMemoryError: unable to create new native thread
    at java.lang.Thread.start0(Native Method)
    at java.lang.Thread.start(Thread.java:597)
    at com.microsoft.sqlserver.jdbc.TimeoutTimer.start(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
    at org.hibernate.loader.Loader.doQuery(Loader.java:697)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.doList(Loader.java:2228)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
    at org.hibernate.loader.Loader.list(Loader.java:2120)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)

Is it possible that sqljdbc leaks native threads?

解决方案

According to this thread, the use of setQueryTimeout on the statement makes the executeQuery open a thread for each query. This can lead to a massive threads usage by the driver and cause memory problems. Not sure it's the case here and not sure it's under your control anyway. So actually, you may have to reduce the Thread stack size to avoid this problem.

Try to add -Xss128k to your JVM settings.

See this thread and this one for more informations on Thread stack sizing and hardware limitations.

这篇关于SQL Server JDBC:无法创建新的本地线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆