I created two threads in main activity to manipulate shared field member but value seems not updated by threads, because variable's value is same, actually im practicing synchronization, here is my code:
public class ActMain extends Activity {
Handler handler;
Integer THREAD_COUNTER = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_main);
Message m = new Message();
Bundle b = new Bundle();
b.putInt("what", 5);
m.setData(b);
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
for(int i =0; i < 10; i++){
add();
}
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < 30; i++){
subtract();
}
}
});
t1.start();
t2.start();
Log.i("MainActivity " , " thread counter" + THREAD_COUNTER);
//same value 10 of THREAD_COUNTER