users@ejb-spec.java.net

[ejb-spec users] [jsr345-experts] Re: Transaction timeout

From: David Blevins <david.blevins_at_gmail.com>
Date: Mon, 12 Dec 2011 18:41:42 -0800

On Dec 12, 2011, at 6:11 PM, Marina Vatkina wrote:

> Jean-Louis MONTEIRO wrote:
>> Users would love being able to set the transaction timeout.
>>
>> May be some points to clarify in the spec:
>> - interceptors are part of the transaction
>> - in transaction managers, the timeout is usually checked before commit. As soon as the commit statement is sent, no more ways to interrupt it
>
> I don't think you can change transaction timeout of a running transaction.

That's the case for us as well (Geronimo Transaction Manager). Once the transaction is started, the timeout is set in stone.

I can imagine this working portably at the start of the transaction. Anything else would seem to be getting into vendor-specific territory.


-David

>>
>> 2011/12/9 David Blevins <david.blevins_at_gmail.com <mailto:david.blevins_at_gmail.com>>
>>
>> It's a good concept.
>>
>> The fact that many @TransactionAttributes can effectively affect a
>> single transaction seems to lead me to the conclusion that the
>> timeout should be a different annotation. Otherwise I suspect
>> there will be several frustrated people who can't figure out why
>> the timeout doesn't work when they put it on SUPPORTS or worse
>> REQUIRED in situations where that particular method didn't start
>> the transaction.
>>
>> Perhaps @TransactionTimeout to be consistent with @StatefulTimeout
>> and @AccessTimeout. We could have put the stateful timeout data
>> on @Stateful. As well we could have put the access timeout info
>> on @Lock. We didn't, so my vote would be for consistency.
>>
>> @Target({METHOD, TYPE})
>> @Retention(RUNTIME)
>> public @interface TransactionTimeout {
>> long timeout() default -1L;
>> TimeUnit unit() default TimeUnit.SECONDS;
>> }
>>
>>
>> What I wonder is that it clearly only would work 100% of the time
>> on REQUIRES_NEW and sometimes on REQUIRED. We'll definitely have
>> to document that, but I wonder if we might want to be a bit strict
>> about it.
>>
>> Something like this is a little loose, but workable:
>>
>> @Stateless
>> @TransactionTimeout(30)
>> public class FooBean {
>>
>> @TransactionAttribute(REQUIRES_NEW)
>> public void doSomething() {}
>>
>> @TransactionAttribute(NEVER)
>> public void doSomething() {}
>> }
>>
>> This is flat out wrong:
>>
>> @Stateless
>> public class FooBean {
>>
>> @TransactionAttribute(REQUIRES_NEW)
>> @TransactionTimeout(30)
>> public void doSomething() {}
>>
>> @TransactionAttribute(NEVER)
>> @TransactionTimeout(30)
>> public void doSomething() {}
>> }
>>
>> Not sure what tact is the best to discourage that blatant misuse.
>>
>>
>> -David
>>
>>
>> On Dec 9, 2011, at 3:35 AM, Carlo de Wolf wrote:
>>
>> > Given the functionality of a transaction manager to set the
>> transaction timeout [1]. I would like to expose this feature in a
>> spec defined manner.
>> >
>> > How about the following annotation:
>> >
>> > @Target({METHOD, TYPE})
>> > @Retention(RUNTIME)
>> > public @interface TransactionAttribute {
>> > TransactionAttributeType value() default
>> TransactionAttributeType.REQUIRED;
>> > long timeout() default -1L;
>> > TimeUnit unit() default TimeUnit.SECONDS;
>> > }
>> >
>> > Where -1 means unspecified.
>> >
>> > And the following descriptor fragment:
>> >
>> > <ejb-jar version="3.2">
>> > <assembly-descriptor>
>> > <container-transaction>
>> > <method>
>> > <ejb-name>A</ejb-name>
>> > <method-name>*</method-name>
>> > </method>
>> > <trans-attribute>RequiresNew</trans-attribute>
>> > <trans-timeout>
>> > <timeout>10</timeout>
>> > <unit>Seconds</unit>
>> > </trans-timeout>
>> > </container-transaction>
>> > </assembly-descriptor>
>> > </ejb-jar>
>> >
>> > What do you guys think?
>> >
>> > Carlo
>> >
>> > [1]
>> http://docs.oracle.com/javaee/6/api/javax/transaction/TransactionManager.html#setTransactionTimeout%28int%29
>> >
>> > PS. Since people are going to dig, we discussed changing
>> transaction attributes on Oct 17th 2007.
>>
>>