2 Replies Latest reply on Sep 14, 2007 7:01 AM by ChaoHuang

    CurrentTransaction bug

      There seems to be a bug in the CurrentTransaction implementation (JE 3.2.44). The Javadoc for the method getInstance() states "This method always returns the same reference when called more than once with the same environment parameter." but it is not the case. The following code reproduces the problem.

      import java.io.File;
      import java.util.Properties;

      import com.sleepycat.collections.CurrentTransaction;
      import com.sleepycat.je.Environment;
      import com.sleepycat.je.EnvironmentConfig;

      public class Bdb {

      public static void main(String[] args) throws Exception {
      int wait = 10;
      if(args.length > 0) {
      wait = Integer.valueOf(args[0]);

      Properties p = new Properties();
      p.setProperty("je.env.isTransactional", "true");
      p.setProperty("je.env.isLocking", "true");
      p.setProperty("je.env.isReadOnly", "false");
      p.setProperty("je.env.recovery", "true");

      EnvironmentConfig cfg = new EnvironmentConfig(p);
      Environment env = new Environment(new File("."), cfg);

      CurrentTransaction ct = CurrentTransaction.getInstance(env);
      int hash = ct.hashCode();
      int hash2 = -1;
      try {
      ct = null;
      // Try to get the GC to collect the CurrentTransaction instance... There is no way to guarantee it'll happen.
      for(int i = 0; i < wait; i++) {
      ct = CurrentTransaction.getInstance(env);
      hash2 = ct.hashCode();
      System.out.println("Instance was not collected. Try increasing the wait time...");
      } catch(IllegalStateException e) {
      System.out.println("Error commiting transaction: " + e.getMessage());
      System.out.println(hash + " != "+ hash2);


        • 1. Re: CurrentTransaction bug

          Thanks for reporting this. We will look into it this week.

          If the problem is what I think it is, a workaround is to keep a reference to the CurrentTransaction around in your program as long as you keep the Environment open. You probably already knew that (based on reading your test), but I wanted to mention it.

          • 2. Re: CurrentTransaction bug
            We have a fix for this issue and it will be built into the next patch release (as yet not scheduled). If you need a fix before then, we can either send you diffs or we can send you a patched je.jar. Please let me know if you need this (chao.huang at-sign oracle.com) and I'll send it off to you.