Rahul
Rahul

Reputation: 45

transactions using deuce stm

I am trying to revert object state on exceptions. My code is like::

public class DeuceTXTest
{
 @Atomic
 public void myTransactionMethod(HashMap<String, String> myHashMap)
         {
  myHashMap.put("s2", "two");
  if(8>5) 
                  throw new NullPointerException();
 }

  public static void main(String[] args){
   HashMap<String, String> hashMap = new HashMap<String, String>();
   hashMap.put("s1", "one");
   System.out.println("Prior TX :: "+hashMap);
   DeuceTXTest txTest = new DeuceTXTest();
   try {
    txTest.myTransactionMethod(hashMap);
   } catch (Exception e) {
    System.out.println(e);
   }
   System.out.println("Post TX :: "+hashMap);
  }
}

I added -javaagent:myDir/deuceAgent.jar as the VMArgument while running on eclipse.

Result Expected::

Prior TX :: {s1=one}
               java.lang.RuntimeException
               Post TX :: {s1=one}

Actual Result ::

Prior TX :: {s1=one}
       java.lang.RuntimeException
       Post TX :: {s2=two, s1=one}.

Also, please suggest me better examples on deuce to revert / restore object state on transaction rollback or when exception is thrown.

Upvotes: 1

Views: 948

Answers (1)

Guy Korland
Guy Korland

Reputation: 9568

Deuce semantic is commit on user Exception, same as with single global lock. This was done like this since Exception in Java are legitimate flow control.

If you want to roll back the transaction you can throw TransactionException or AbrotTransactionException.

BTW, since you're using as part of your transaction a class that is part of the rt.jar (and loaded in the bootclasspath) you should offline instrument the rt.jar or at least this class as add it to the bootclassloader.

See: http://www.deucestm.org/documentation/getting-started

Upvotes: 3

Related Questions