Back to the basics. Java performs tasks correctly - no error can be expected in this part of Java. When you write x=a , and a is -3, then x will be immediately 3. Several things that I see in your code that may go wrong:
Multiple threads
Change your code with AtomicInteger and change the caller, so setting up and receiving while waiting for the same value is one atomic call to the AtomicInteger method, not separate method calls. synchronized will not work in the case of the screenshot above.
Track problem
Write a and dataAction before assignment. And if you want to be sure, right after the job again, but keep in mind that another thread could jump in the middle, as well as setDataAction() . I assume that you will find either some strange settings 0 or not call with -3.
Now that you see the wrong destination, add a little code to your setDataAction() .
// add in setDataAction() if(a == the-wrong-value) try { throw new Exception("wrong assignment: " + a); } catch(Exception e) { e.printStackTrace(); }
So, you will find out where the wrong assignment comes from, and you can keep track of what is actually happening.
source share