开发者

transactions using deuce stm

开发者 https://www.devze.com 2023-02-07 14:21 出处:网络
I am trying to revert object state on exceptions. My code is like:: public class DeuceTXTest { @Atomic public void myTransactionMethod(HashMap<String, String> myHashMap)

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消