Newbie: @Atomic annotation does not seem to work

157 views
Skip to first unread message

Prajyoti Waghmare

unread,
Jan 4, 2013, 12:41:38 AM1/4/13
to deuc...@googlegroups.com
Hi,

I am a postgrad and am planning to use deuce for my thesis work. I have written a test program for testing the @Atomic annotation. The test program is the simple Bank transaction example which can run into problems unless synchronized.

public class Bank{
   @Atomic
    public void transfer(BankAccount a1, BankAccount a2, double amount, String str){
        double bal;
        bal = a1.amount - amount;
        for(int i = 0; i < 1000000000; i++){ }   //to spend some time
        a1.amount = bal;
        bal = a2.amount + amount;
        for(int i = 0; i < 1000000000; i++){  }   //to spend some time
        a2.amount = bal;
    }
}

I created two instances of BankAccount a1 and a2 with initial amount 100 and 1000 respectively.
Calling Bank.transfer(a1, a2, 50) and Bank.transfer(a1, a2, 10) should give final result as a1 = 40 and a2 = 1060
which is not the case!! I get final values for(a1, a2) as (50, 1010) or (50, 1060) or (40, 1060) or (90, 1050)!!
If instead I use the synchronized keyword for the above function, I get the correct answer.
Kindly tell me the mistake that I am making.
Thanking you in advance! :)

Guy Korland

unread,
Jan 4, 2013, 12:44:52 AM1/4/13
to deuc...@googlegroups.com
How did you run your code?
Please see: 

Prajyoti Waghmare

unread,
Jan 4, 2013, 12:54:26 AM1/4/13
to deuc...@googlegroups.com
I am using eclipse so I googled on using external annotations and figured out that I need to import the jar in Java Build Path.
Is it not the same as doing java -jar deuceAgent.jar my.jar out_my.jar ??

Prajyoti Waghmare

unread,
Jan 4, 2013, 1:32:20 AM1/4/13
to deuc...@googlegroups.com
I was now successfully able to run the command java -jar deuceAgent.jar my.jar out_my.jar 
Then I tried to run java -jar out_my.jar which gave me the following error
-----------------
Exception in thread "main" java.lang.NoClassDefFoundError: org/deuce/transaction/Context
Caused by: java.lang.ClassNotFoundException: org.deuce.transaction.Context
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Transaction. Program will exit.
-----------
Thanks for the help :)

Guy Korland

unread,
Jan 4, 2013, 2:44:10 AM1/4/13
to deuc...@googlegroups.com
you need to set the deuceAgent by adding:  -javaagent:bin/deuceAgent.jar

--
You received this message because you are subscribed to the Google Groups "Deuce-STM" group.
To view this discussion on the web visit https://groups.google.com/d/msg/deuce-stm/-/FfK7XKOBZ1MJ.

To post to this group, send email to deuc...@googlegroups.com.
To unsubscribe from this group, send email to deuce-stm+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/deuce-stm?hl=en.

Prajyoti Waghmare

unread,
Jan 4, 2013, 3:20:28 AM1/4/13
to deuc...@googlegroups.com
Got it working :)
Thank you so much :)
Reply all
Reply to author
Forward
0 new messages