我想恢復對象狀態的異常。我的代碼是這樣::交易使用deuce stm
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);
}
}
我加-javaagent:myDir/deuceAgent.jar
作爲VMArgument在Eclipse上運行時。
結果預計::
Prior TX :: {s1=one}
java.lang.RuntimeException
Post TX :: {s1=one}
實際結果::
Prior TX :: {s1=one}
java.lang.RuntimeException
Post TX :: {s2=two, s1=one}.
另外,請建議我更好的例子平手恢復/對事務回滾或者拋出異常恢復對象的狀態。
使用4個縮進來格式化您的源代碼。 – 2011-01-27 12:16:52