Question: ```
import java.util.ArrayList;

public class ThreadTest {

    public static void main(String[] args) {

        ArrayList arr = new ArrayList();        
        for (int  i =0; i<10 ; i++)
            arr.add(new MyTh(i));   
        for (int  i =0; i<10 ; i++) {
            ((Thread ) arr.get(i)).start();
        }
    }

}

class MyTh extends Thread {

   int num;

   volatile int  age;

   MyTh (int  k)

   {this.num=k; } 
   @Override
   public void run() {
    if(this.num==4){
        setAge(40);
    }
    System.out.println(Thread.currentThread().getName() + " :"+this.num + ":" + getAge());
}
    synchronized int getAge() {
       return age;
    }
    synchronized void  setAge(int  k) {
        this.age =k;
    }
}

```

I am puzzled here why the output of the program is printing value of volatile variable age = 40 only once .
I tried keeping synchronized in getter / setter both , then too only single thread 4th prints it 40 . Why not other subsequent thread read it 40 too ?

```
Thread-0 :0:0
Thread-1 :1:0
Thread-2 :2:0
Thread-3 :3:0
Thread-4 :4:40
Thread-5 :5:0
Thread-6 :6:0
Thread-7 :7:0
Thread-8 :8:0
Thread-9 :9:0

```

Answer: 
Why you use `synchronized` keyword for getters and setters while your variable is declared `volatile`. It is not needed here. You just need the visibility, not atomicity. So change your code like so,

```
public class MyTh extends Thread {
    int num;

    static volatile int age;

    MyTh(int k)

    {
        this.num = k;
    }

    @Override
    public void run() {
        if (this.num == 4) {
            setAge(40);
        }
        System.out.println(Thread.currentThread().getName() + " :" + this.num + ":" + getAge());
    }

    int getAge() {
        return age;
    }

    void setAge(int k) {
        age = k;
    }
}

```

First mark the `age` variable as `static` so that the same is shared among all the instances of the class. In your previous case it was an instance field, hence each instance had it's own copy. Hence change made by one is not visible to the others.

Latest output is given below.

```
Thread-0 :0:0
Thread-3 :3:0
Thread-2 :2:0
Thread-1 :1:0
Thread-4 :4:40
Thread-6 :6:40
Thread-8 :8:40
Thread-5 :5:40
Thread-7 :7:40
Thread-9 :9:40

```
You have instance copy of age , Hence it is not shared copy , Use static keyword to make age class variable , 

Try below code What you want I guess 

```
import java.util.ArrayList;

```

public class MyTh extends Thread
{
 int num;

```
static volatile int age;

MyTh(int k)

{
    this.num = k;
}

@Override
public void run()
{
    if (this.num == 4)
    {
        setAge(40);
    }
    System.out.println(Thread.currentThread().getName() + " :" + this.num + ":" + getAge());
}

synchronized int getAge()
{
    return age;
}

synchronized void setAge(int k)
{
    this.age = k;
}

public static void main(String[] args)
{

    ArrayList arr = new ArrayList();
    for (int i = 0; i < 10; i++)
        arr.add(new MyTh(i));
    for (int i = 0; i < 10; i++)
    {
        ((Thread) arr.get(i)).start();
    }
}

```

}