【问题标题】:Spring freezing application春季冷冻应用
【发布时间】:2011-02-09 01:03:33
【问题描述】:

在一些特定的请求后,我的应用程序被冻结了,这让我很痛苦。 调试表明代码在调用 Spring bean(单例)方法的行上没有任何堆栈跟踪或线程终止:

myDaoService.getUserById(id)

我猜它正在中断,而不是冻结,因为分析器显示同一线程正在尝试处理后续请求。
无法追踪是什么原因造成的。
幸运的是我发现了原因:我在事务范围之外调用了其中一个 DAO 方法,但它以只读模式访问它。

现在,问题:

Do you have any clue why wasn't that traceable by debugger?

Why a method accessing db in read-only mode out of transaction caused such behavior?

Is there a way to completely forbid querying out of transaction scope?

无论我做错了什么,我真的很害怕在响应我的错误操作时没有抛出任何异常或任何其他错误输出!

我的休眠配置:

<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.connection.pool_size">32</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.1/db_test</property>
<property name="hibernate.connection.password">xxxxxx</property>
<property name="hibernate.connection.username">xxxxxx</property>

春季版是3.0
休眠版本是 3.6
Tx Manager 是 org.springframework.orm.hibernate3.HibernateTransactionManager

【问题讨论】:

  • 那么,您为解决问题所做的只是将@Transactional 注解添加到您的DAO 方法中?
  • @Luciano Fiandesio,是的)

标签: java hibernate spring orm


【解决方案1】:

你知道为什么不是这样吗 可被调试器追踪?

不,但也许通过线程转储可以告诉你。

为什么以只读方式访问数据库的方法 交易模式导致这样的 行为?

我会添加一个事务上下文,然后再试一次。不要以为它没问题,因为它是只读的。它花费很少,因为事务是声明性的。将事务管理添加到所有 DAO 方法中,看看是否有帮助。

【讨论】:

  • 是的,正如我所说,这就是原因 - 修复事务范围解决了问题。我最关心的是如何追踪它?
猜你喜欢
  • 2020-07-02
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-31
  • 2015-12-23
  • 2018-11-15
  • 1970-01-01
相关资源
最近更新 更多