While passing a volatile variable to another class (both extend Thread Class), do I have to import this volatile variable as a volatile or just public definition would be enough?
ex:
public class A extends Thread{
public volatile int a = 0;
public void run(){
B bObj = new B(a);
a++;
}
}
Now the class receiving a volatile variable, should use define the receiver variable as volatile or just public? like this
public class B extends Thread{
public volatile int a;
public B(int a){
this.a =a ;
}
}
OR should be defined like this?
public class B extends Thread{
public int a;
public B(int a){
this.a =a ;
}
}
With both classes exchanging the variable over some period of time or the other.
Any help is highly appreciated. Thanks