|
The determineRemainingTransactionTimeOutPeriod method has rounding off error as it divides by 1000 and type casts the result to int.
public int determineRemainingTransactionTimeOutPeriod() {
if ( transactionTimeOutInstant < 0 ) {
return -1;
}
final int secondsRemaining = (int) ((transactionTimeOutInstant - System.currentTimeMillis()) / 1000);
if ( secondsRemaining <= 0 ) {
throw new TransactionException( "transaction timeout expired" );
}
return secondsRemaining;
}
If the transaction timeout is set to 1 sec, this method will always return remaining seconds as 0. A better fix is not to divide by 1000 and use long type for determining the timeout in ms.
Also, if possible it should through a sub-class TransactionTimeoutException of TransactionException, similar to org.springframework.transaction.TransactionTimedOutException. Now, the only way to determing if the transaciton has been timedout programatically is to check for that string in the exception message.
|