-->

How to change value of com.arjuna.ats.jbossatx.jta

2019-06-11 09:34发布

问题:

We have JBoss [EAP] 4.3.0.GA_CP01 environment and I need to modify the

TransactionTimeout 

property of

com.arjuna.ats.jbossatx.jta.TransactionManagerService

but whenever i try to change the value via MBean from JMX-Console; following stacktrace shows up:

java.lang.IllegalStateException: Cannot set transaction timeout once MBean has started
com.arjuna.ats.jbossatx.jta.TransactionManagerService.setTransactionTimeout(TransactionManagerService.java:323)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.jboss.mx.interceptor.AttributeDispatcher.invoke(AttributeDispatcher.java:136)
org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
org.jboss.mx.interceptor.ModelMBeanAttributeInterceptor.invoke(ModelMBeanAttributeInterceptor.java:103)
org.jboss.mx.interceptor.PersistenceInterceptor.invoke(PersistenceInterceptor.java:76)
org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
org.jboss.mx.server.AbstractMBeanInvoker.setAttribute(AbstractMBeanInvoker.java:461)
org.jboss.mx.server.MBeanServerImpl.setAttribute(MBeanServerImpl.java:608)
org.jboss.jmx.adaptor.control.Server.setAttributes(Server.java:206)
org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.updateAttributes(HtmlAdaptorServlet.java:236)
org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.processRequest(HtmlAdaptorServlet.java:98)
org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.doPost(HtmlAdaptorServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Is there a way programmatically to change the value of TransactionTimeout without bouncing the server at the run-time??

回答1:

Here's a groovy example of how to do this (using embedded groovy inside a JBoss 4.3.0.GA_CP01 instance):

mbeanserver.getAttribute(JMXHelper.objectName("jboss:service=TransactionManager"), "TransactionManager").setTransactionTimeout(200);

Basically, the MBeanService com.arjuna.ats.jbossatx.jta.TransactionManagerService does not allow you to change the default transaction timeout, but if you retrieve the attribute TransactionManager (an instance of com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate), it exposes the method:

public void com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.setTransactionTimeout(int) throws javax.transaction.SystemException

Note that this will not change the value reported in the MBean's TransactionTimeout attribute, but all transactions started after this method is called will have the new transaction timeout.

More groovy code:

def txManager = mbeanserver.getAttribute(JMXHelper.objectName("jboss:service=TransactionManager"), "TransactionManager");
TX.exec({
    println "Timeout:${txManager.getTransactionTimeout()}";
});
txManager.setTransactionTimeout(txManager.getTransactionTimeout() * 2);
TX.exec({
    println "Timeout:${txManager.getTransactionTimeout()}";
});

Output:

Timeout:200
Timeout:400



回答2:

Thank you Nicholas!

Here is the Java code which can be used to change the transaction timeout on runtime...

MBeanServer mBeanServer = MBeanServerLocator.locateJBoss();
TransactionManagerDelegate tmd = (TransactionManagerDelegate) mBeanServer.getAttribute(new ObjectName("jboss:service=TransactionManager"), "TransactionManager");
System.out.println("Prev: " + tmd.getTransactionTimeout());
tmd.setTransactionTimeout(200);
System.out.println("New: " + tmd.getTransactionTimeout());

And as you quoted, Note that this will not change the value reported in the MBean's TransactionTimeout attribute however the value will be effective for all transactions post this operation.