解决com.atomikos.icatch.RollbackException: Prepare: NO vote

    使用atomikos时,事务默认超时时间是100000毫秒,超过这个时间,提交事务就会抛出异常com.atomikos.icatch.RollbackException: Prepare: NO vote

    今天总算通过bing找到了答案,记录一下。

    在网上很多说的要设置com.atomikos.icatch.max_timeout和com.atomikos.icatch.default_jta_timeout,居然都没说怎么设置,集成Spring的情况下,第一时间想到在bean的属性里配置,结果没找到(default_jta_timeout可以在org.springframework.transaction.jta.JtaTransactionManager中找到defaultTimeOut属性与之匹配,但是max_timeout没有找到,官方文档(https://www.atomikos.com/Documentation/JtaProperties)也没说,只是说设置max_timeout和UserTransaction.setTransactionTimeout()是一个意思,结果我配置了半天,没有效果)。最后搞明白了,需要在classpath下建一个jta.properties(或者transactions.properties)文件(事务管理器的配置),来配置事务相关属性,如下是我的jta.properties。

    PS:default_jta_timeout表示开启事务时,默认的超时时间,max_timeout表示最大的超时时间,0表示无限时间。如果default_jta_timeout设置的值超过了max_timeout,会自动将超时时间截断,使用max_timeout的值(日志会打印出来)。

# SAMPLE PROPERTIES FILE FOR THE TRANSACTION SERVICE
# THIS FILE ILLUSTRATES THE DIFFERENT SETTINGS FOR THE TRANSACTION MANAGER
# UNCOMMENT THE ASSIGNMENTS TO OVERRIDE DEFAULT VALUES;

# Required: factory implementation class of the transaction core.
# NOTE: there is no default for this, so it MUST be specified! 
# 
com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory

        
# Set base name of file where messages are output 
# (also known as the 'console file').
#
# com.atomikos.icatch.console_file_name = tm.out

# Size limit (in bytes) for the console file;
# negative means unlimited.
#
# com.atomikos.icatch.console_file_limit=-1

# For size-limited console files, this option
# specifies a number of rotating files to 
# maintain.
#
# com.atomikos.icatch.console_file_count=1

# Set the number of log writes between checkpoints
#
# com.atomikos.icatch.checkpoint_interval=500

# Set output directory where console file and other files are to be put
# make sure this directory exists!
#
# com.atomikos.icatch.output_dir = ./

# Set directory of log files; make sure this directory exists!
#
# com.atomikos.icatch.log_base_dir = ./

# Set base name of log file
# this name will be  used as the first part of 
# the system-generated log file name
#
# com.atomikos.icatch.log_base_name = tmlog

# Set the max number of active local transactions 
# or -1 for unlimited.
#
# com.atomikos.icatch.max_actives = 50

# Set the default timeout (in milliseconds) for local transactions
# 默认的超时时间
com.atomikos.icatch.default_jta_timeout = 3000000

# Set the max timeout (in milliseconds) for local transactions
# 0表示无限
com.atomikos.icatch.max_timeout = 0

# The globally unique name of this transaction manager process
# override this value with a globally unique name
#
# com.atomikos.icatch.tm_unique_name = tm
    
# Do we want to use parallel subtransactions? JTA's default
# is NO for J2EE compatibility
#
# com.atomikos.icatch.serial_jta_transactions=true
                    
# If you want to do explicit resource registration then
# you need to set this value to false.
#
# com.atomikos.icatch.automatic_resource_registration=true  
    
# Set this to WARN, INFO or DEBUG to control the granularity
# of output to the console file.
#
# com.atomikos.icatch.console_log_level=WARN
    
# Do you want transaction logging to be enabled or not?
# If set to false, then no logging overhead will be done
# at the risk of losing data after restart or crash.
#
# com.atomikos.icatch.enable_logging=true

# Should two-phase commit be done in (multi-)threaded mode or not?
# Set this to false if you want commits to be ordered according
# to the order in which resources are added to the transaction.
#
# NOTE: threads are reused on JDK 1.5 or higher. 
# For JDK 1.4, thread reuse is enabled as soon as the 
# concurrent backport is in the classpath - see 
# http://mirrors.ibiblio.org/pub/mirrors/maven2/backport-util-concurrent/backport-util-concurrent/
#
# com.atomikos.icatch.threaded_2pc=false

# Should shutdown of the VM trigger shutdown of the transaction core too?
#
# com.atomikos.icatch.force_shutdown_on_vm_exit=false

 

然后,Spring的配置文件

<!-- Atomikos 事务管理器配置 -->
	<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
		init-method="init" destroy-method="close">
		<!-- <property name="startupTransactionService" value="false" /> -->
		<!-- close()时是否强制终止事务 -->
    	<property name="forceShutdown" value="false" />
	</bean>

	<!-- Atomikos UserTransaction配置 -->
	<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"></bean>

	<!-- JTA事务管理器 -->
	<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="transactionManager">
			<ref bean="atomikosTransactionManager" />
		</property>
		<property name="userTransaction">
			<ref bean="atomikosUserTransaction" />
		</property>
	</bean>
	<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true" />

 

 

转载于:https://my.oschina.net/simpleton/blog/915683

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"Failed to obtain JDBC Connection; nested exception is com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted" 是一个常见的错误信息,它通常表示数据库连接池无法提供足够的连接给应用程序使用。 这个错误可能有以下几个原因: 1. 数据库连接池配置不正确:检查数据库连接池的最大连接数配置是否足够满足应用程序的需求。如果连接数设置过低,可能会导致连接池耗尽。 2. 数据库连接泄漏:应用程序在使用完数据库连接后没有正确地释放连接,导致连接池中的连接无法被重用,最终耗尽连接池资源。 3. 数据库连接超时:如果数据库连接在一段时间内没有被使用,连接池可能会将其关闭,释放资源。当应用程序再次请求连接时,可能会出现连接池耗尽的情况。 4. 数据库服务器负载过高:如果数据库服务器负载过高,无法及时处理应用程序的连接请求,可能会导致连接池无法获取到足够的连接。 为了解决这个问题,你可以尝试以下几个步骤: 1. 检查数据库连接池的配置,确保最大连接数足够满足应用程序的需求。 2. 检查应用程序中是否存在数据库连接泄漏的情况,确保在使用完数据库连接后及时释放连接。 3. 调整数据库连接超时时间,确保连接池中的连接能够被重用。 4. 检查数据库服务器的负载情况,如果负载过高,考虑优化数据库服务器的性能或者增加服务器资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值