赞
踩
使用atomikos时,事务默认超时时间是100000毫秒,超过这个时间,提交事务就会抛出异常
nested exception is javax.transaction.RollbackException: Prepare: NO vote
1、增加配置文件transactions.properties(jta.properties)
需要在classpath下建一个transactions.properties(或者jta.properties)文件(事务管理器的配置),来配置事务相关属性,如下是我的transactions.properties
# 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 #com.atomikos.icatch.max_timeout=2000 # 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 = 10000 # Set the max timeout (in milliseconds) for local transactions # # com.atomikos.icatch.max_timeout = 300000 # 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=false # 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 # 配置最大的事务活动个数,-1代表无限制(atomikos版本3.9.3) com.atomikos.icatch.max_actives = -1 # 默认的超时时间单位毫秒 com.atomikos.icatch.default_jta_timeout = 3000000 # Set the max timeout (in milliseconds) for local transactions # 0不起作用(网上有很多说将这个配置成0表示无限制,但是我配置后还是会报com.atomikos.icatch.RollbackException: Prepare: NO vote可能是atomikos版本不一样的缘故吧 我用的版本是3.9.3)所以我将其配置成大于0的数 com.atomikos.icatch.max_timeout = 3000000
2、修改spring-**.xml文件
这个文件是spring的配置文件名字叫什么都可以
(1)<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown"> <!-- 将close()时是否强制终止事务设置为false--> <value>false</value> </property> </bean>
(2)
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <!--将该属性注释掉 <property name="transactionTimeout" value="5000" />--> </bean>
我通过以上配置后atomikos事务提交正常
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。