1

As per the org.apache.geronimo.transaction.manager.TransactionTimer, following is the implementation:

package org.apache.geronimo.transaction.manager;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class TransactionTimer {
  private static volatile long currentTime;
  public TransactionTimer() {}
  public static long getCurrentTime() {
    return currentTime;
  }
  static {
    AccessController.doPrivileged(new PrivilegedAction() {
      public Object run() {
        TransactionTimer.CurrentTime tm = new TransactionTimer.CurrentTime();
        tm.setDaemon(true);
        tm.start();
        return null;
      }
    });
  }
  private static class CurrentTime extends Thread {
    protected CurrentTime() {
      TransactionTimer.currentTime = System.currentTimeMillis();
      this.setContextClassLoader((ClassLoader) null);
    }
    public void run() {
      while (true) {
        TransactionTimer.currentTime = System.currentTimeMillis();
        try {
          * Thread.sleep(1000 L);*
        } catch (InterruptedException var2) {
          ;
        }
      }
    }
  }
}


Which shows that the currentTime is always incremented by 1 sec, and so the lib do not support a timeout less than 1 sec. How I can set timeout less than 1 sec ?

    TransactionImpl(Xid xid, TransactionManagerImpl txManager, long transactionTimeoutMilliseconds) throws SystemException {
        this.syncList = new ArrayList(5);
        this.interposedSyncList = new ArrayList(3);
        this.resourceManagers = new LinkedList();
        this.activeXaResources = new IdentityHashMap(3);
        this.suspendedXaResources = new IdentityHashMap(3);
        this.status = 6;
        this.resources = new HashMap();
        this.txManager = txManager;
        this.xid = xid;
        this.timeout = transactionTimeoutMilliseconds + TransactionTimer.getCurrentTime();

Didn't find any way to set a value less than 1 sec.

1 Answers1

0

Timeout of less than one second

There is the possibility to achieve this, however increased CPU usage will probably be a side effect since the Thread would wake up more often.

How To: Support a timeout less than 1 second

1. Modify Sleep Duration:
In the CurrentTime thread reduce the sleep duration from 1000ms (1 second) to a smaller value that matches the granularity you want. For example 10ms or even 1ms. In this example I will use 10ms.

Code Change:

Thread.sleep(10L); // This would make the granularity 10ms

Now if there is a specific logic that depends on TransactionTimer.getCurrentTime() you might need to modify that too. The timeout is set as a sum of transactionTimeoutMilliseconds and the current time in the constructor if TransactionImpl. This logic should still hold.

2. Check other Dependencies:
Since we are modifying a library we have to ensure that other parts of the library or your application don't depend on the one second granularity of TransactionTimer.getCurrentTime(). If they do, those parts need to be adjusted.

As I said before there might be a performance problem, especially if you go very low with the granularity. Also maybe check out libraries that potentially offer something like this.

AztecCodes
  • 1,130
  • 7
  • 23