2

I am trying to do some sample work on bitronix transaction management with spring + hibernate + mysql as standalone application.

My Spring configuration is:

<bean id="bitronixTMConfig"
    class="bitronix.tm.TransactionManagerServices" factory-method="getConfiguration">
    <property name="disableJmx" value="true" />
    <property name="serverId" value="btm-sever"></property>
</bean>

<bean id="bitronixTM" class="bitronix.tm.TransactionManagerServices"
    factory-method="getTransactionManager" destroy-method="shutdown" depends-on="bitronixTMConfig" />

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"
    depends-on="bitronixTM,xaDataSource">
    <property name="transactionManager" ref="bitronixTM" />
    <property name="userTransaction" ref="bitronixTM" />
    <property name="allowCustomIsolationLevels" value="true" />
</bean>

<bean id="xaDataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
    init-method="init" destroy-method="close">
    <property name="className" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
    <property name="uniqueName" value="jdbc/xaDataSource" />    
    <property name="minPoolSize" value="3" />
    <property name="maxPoolSize" value="5" />
    <property name="testQuery" value="SELECT 1 FROM DUAL" />
    <property name="driverProperties">
        <props>
            <prop key="URL">jdbc:mysql://localhost:3306/sample</prop>
            <prop key="user">root</prop>
            <prop key="password">admin123</prop>
        </props>
    </property>
    <property name="allowLocalTransactions" value="true" />
</bean>

<bean id="entityManager" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="xaDataSource" />
    <property name="packagesToScan" value="com.sample.entities" />
    <property name="jtaTransactionManager" ref="transactionManager" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.connection.release_mode">after_statement</prop>
            <prop key="hibernate.current_session_context_class">jta</prop>
            <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.BTMTransactionManagerLookup</prop>
        </props>
    </property>
</bean>

<bean id="sample" class="com.sample.tx.TransactionTest" />

Transaction Test has no code yet but i will write the transaction code there

package com.sample.tx;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

public class TransactionTest implements InitializingBean{


public void start(){

}



@Override
public void afterPropertiesSet() throws Exception {
    start();
    System.out.println("hello world");
}   
}

But when i try to run application using ClassPathXmlApplicationContext and try to put debug point on the sysout line above the code is not executing it gets suck with the bitronix logs as follows

23:41:41.234 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [http://www.springframework.org/schema/beans/spring-beans-4.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-4.0.xsd
23:41:41.288 [main] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions
23:41:41.311 [main] DEBUG o.s.b.f.xml.XmlBeanDefinitionReader - Loaded 6 bean definitions from location pattern [applicationContext.xml]
23:41:41.311 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@33f88ab: org.springframework.beans.factory.support.DefaultListableBeanFactory@327514f: defining beans [bitronixTMConfig,bitronixTM,transactionManager,xaDataSource,entityManager,sample]; root of factory hierarchy
23:41:41.355 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@424e1977]
23:41:41.358 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@6a2b953e]
23:41:41.360 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@327514f: defining beans [bitronixTMConfig,bitronixTM,transactionManager,xaDataSource,entityManager,sample]; root of factory hierarchy
23:41:41.361 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'bitronixTMConfig'
23:41:41.361 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'bitronixTMConfig'
23:41:41.380 [main] DEBUG bitronix.tm.Configuration - loading default configuration
23:41:41.380 [main] DEBUG bitronix.tm.Configuration - no configuration file found, using default settings
23:41:41.381 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'bitronixTMConfig' to allow for resolving potential circular references
23:41:41.431 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'bitronixTMConfig'
23:41:41.431 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'bitronixTMConfig'
23:41:41.431 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'bitronixTM'
23:41:41.431 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'bitronixTM'
23:41:41.435 [main] INFO  b.tm.BitronixTransactionManager - Bitronix Transaction Manager version 2.1.4
23:41:41.435 [main] DEBUG b.tm.BitronixTransactionManager - JVM version 1.8.0_60
23:41:41.435 [main] INFO  bitronix.tm.Configuration - JVM unique ID: <btm-sever>
23:41:41.438 [main] DEBUG b.tm.BitronixTransactionManager - starting BitronixTransactionManager using a Configuration with [allowMultipleLrc=false, asynchronous2Pc=false, backgroundRecoveryInterval=1, backgroundRecoveryIntervalSeconds=60, currentNodeOnlyRecovery=true, debugZeroResourceTransaction=false, defaultTransactionTimeout=60, disableJmx=true, exceptionAnalyzer=null, filterLogStatus=false, forceBatchingEnabled=true, forcedWriteEnabled=true, gracefulShutdownInterval=60, jndiTransactionSynchronizationRegistryName=java:comp/TransactionSynchronizationRegistry, jndiUserTransactionName=java:comp/UserTransaction, journal=disk, logPart1Filename=btm1.tlog, logPart2Filename=btm2.tlog, maxLogSizeInMb=2, resourceConfigurationFilename=null, serverId=btm-sever, skipCorruptedLogs=false, warnAboutZeroResourceTransaction=true]
23:41:41.439 [main] DEBUG b.tm.TransactionManagerServices - using journal disk
23:41:41.440 [main] DEBUG bitronix.tm.journal.DiskJournal - disk journal files max length: 0

after this lines in console nothing happens i dont get any afterPropertySet in the Test class. What issue would it be ? or am i missing something.

edit: thread dump

2015-11-26 07:30:39 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode):

"RMI TCP Connection(2)-192.168.130.1" #16 daemon prio=5 os_prio=0 tid=0x000000000c60b000 nid=0x2dc8 runnable [0x000000000e42d000]
   java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
- locked <0x00000000d5fb6630> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/953184998.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
- <0x00000000d5f0ff50> (a java.util.concurrent.ThreadPoolExecutor$Worker)

"JMX server connection timeout 15" #15 daemon prio=5 os_prio=0 tid=0x000000000c08a800 nid=0x64 in Object.wait() [0x000000000e32f000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000d7d88178> (a [I)
at com.sun.jmx.remote.internal.ServerCommunicatorAdmin$Timeout.run(ServerCommunicatorAdmin.java:168)
    - locked <0x00000000d7d88178> (a [I)
at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
- None

"RMI Scheduler(0)" #14 daemon prio=5 os_prio=0 tid=0x000000000bd92000 nid=0x3a2c waiting on condition [0x000000000e22f000]
   java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for  <0x00000000d7d80dc8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
- None

"RMI TCP Connection(1)-192.168.130.1" #13 daemon prio=5 os_prio=0 tid=0x000000000c3e5800 nid=0x2b3c runnable [0x000000000df2e000]
   java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
- locked <0x00000000d7d90800> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/953184998.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
- <0x00000000d7d90958> (a java.util.concurrent.ThreadPoolExecutor$Worker)

"RMI TCP Accept-0" #12 daemon prio=5 os_prio=0 tid=0x000000000c157000 nid=0x1218 runnable [0x000000000d8be000]
   java.lang.Thread.State: RUNNABLE
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
- locked <0x00000000d7d982b0> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:52)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:400)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:372)
at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
- None

"Service Thread" #10 daemon prio=9 os_prio=0 tid=0x000000000b182800 nid=0x288c runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
- None

"C1 CompilerThread3" #9 daemon prio=9 os_prio=2 tid=0x00000000089cc800 nid=0x1284 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

"C2 CompilerThread2" #8 daemon prio=9 os_prio=2 tid=0x000000000b0fb000 nid=0x35ec waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

"C2 CompilerThread1" #7 daemon prio=9 os_prio=2 tid=0x000000000b0f6800 nid=0x1720 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

"C2 CompilerThread0" #6 daemon prio=9 os_prio=2 tid=0x000000000b0f1000 nid=0x2a00 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
    - None

"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000000b0ef800 nid=0x37c waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000000b0ee800 nid=0x63c runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x00000000029cc000 nid=0x23e0 in Object.wait() [0x000000000a99e000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000d7da0bc8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000000d7da0bc8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

   Locked ownable synchronizers:
    - None

"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x00000000029c5000 nid=0x26c8 in Object.wait() [0x000000000a89f000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000d7da8178> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
- locked <0x00000000d7da8178> (a java.lang.ref.Reference$Lock)

   Locked ownable synchronizers:
    - None

"main" #1 prio=5 os_prio=0 tid=0x00000000028d3800 nid=0x1e08 runnable [0x00000000028be000]
   java.lang.Thread.State: RUNNABLE
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.FileDispatcherImpl.read(FileDispatcherImpl.java:61)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:197)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:159)
- locked <0x00000000d7da0d18> (a java.lang.Object)
at bitronix.tm.journal.TransactionLogHeader.<init>(TransactionLogHeader.java:101)
- locked <0x00000000d7da0d98> (a sun.nio.ch.FileChannelImpl)
at bitronix.tm.journal.TransactionLogAppender.<init>(TransactionLogAppender.java:70)
at bitronix.tm.journal.DiskJournal.open(DiskJournal.java:157)
- locked <0x00000000d7da0fd0> (a bitronix.tm.journal.DiskJournal)
at bitronix.tm.BitronixTransactionManager.<init>(BitronixTransactionManager.java:85)
at bitronix.tm.TransactionManagerServices.getTransactionManager(TransactionManagerServices.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
- locked <0x00000000d7da1330> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
- locked <0x00000000d7da1448> (a java.lang.Object)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.sample.tx.Main.main(Main.java:9)

   Locked ownable synchronizers:
    - <0x00000000d7f67020> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)

"VM Thread" os_prio=2 tid=0x00000000089b9800 nid=0x32b4 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000028e9800 nid=0x3260 runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000028eb800 nid=0x2018 runnable 

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000028ed000 nid=0x1ec8 runnable 

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00000000028ee800 nid=0x31d8 runnable 

"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x00000000028f0800 nid=0xc38 runnable 

"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x00000000028f3000 nid=0x2730 runnable 

"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x00000000028f6000 nid=0x614 runnable 

"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x00000000028f7000 nid=0x3860 runnable 

"VM Periodic Task Thread" os_prio=2 tid=0x000000000b19e800 nid=0x18d8 waiting on condition 

JNI global references: 238
Neenad
  • 861
  • 5
  • 19
  • Once it is stuck can you capture a stack dump? If this is a Linux server you can do this with "kill -QUIT " if this is a Windows server you can use the jstack and jps programs that come in your JDK installation. The stack dump will tell you what the server is trying to do and may show a deadlock. – Pace Nov 25 '15 at 19:04
  • provided with thread dumps – Neenad Nov 26 '15 at 02:07

2 Answers2

3

It's working now the problem was because of the logPartFile creation, bitronix by default I think bitronix creates the file btm1.tlog btm2.tlog in some path where it didnt have write permission to create the file using NIO or read permission so thread was getting stuck at that point now i changed the config a bit and its working

<bean id="bitronixTMConfig"
    class="bitronix.tm.TransactionManagerServices" factory-method="getConfiguration">
    <property name="disableJmx" value="true" />
    <property name="serverId" value="btm-sever" />
    <property name="logPart1Filename" value="c:/temp/btm1.tlog" />
    <property name="logPart2Filename" value="c:/temp/btm2.tlog" />
</bean>
Neenad
  • 861
  • 5
  • 19
  • Thanks, mine wasn't the exact same issue as yours, but this helped me out. Turns out one of my btm log files got set as read only, so bitronix decided to sit there and do nothing without telling me that. – Andrew Mairose May 12 '17 at 19:26
  • Deleting those two files on the disk and letting Bitronix recreate them fixed the hang for me. – Trenton Telge Oct 20 '21 at 16:25
0

delete the btmlogger file and run again , this resolved issue for me