I have multiple classes that have a common variable with the same name.
Say a string variable “str”.
I have a thread class say “thread_update_str”
What I need to do is make the str variable in the class from which it is called to the current datetime from the method run of the thread.
Could anyone help me figure how could I achieve something like this
Any help would be appreciated …
Thanks a lot
Also I do not necessarily need the value of str to be same across all classes.
Class abc
{
String str = "a";
new str_Thread().start();
System.out.println(str);
}
Class xyz
{
String str = "x";
new str_Thread().start();
System.out.println(str);
}
Class lmn
{
String str = "l";
new str_Thread().start();
System.out.println(str);
}
public class str_Thread extends Thread {
public void run() {
for (int i = 1; i > 0; i++) {
try {
//make the str variable equal to i.toString();
sleep((int)(10000));
System.out.println("DONE!"+i);
} catch (Exception e) {e.printStackTrace();}
}
}
}
Your classes should implement an interface with the method
And your thread-class gets the object where to set the String as constructor arg.