Accessing a variable of a thread from another thread in java
问题 I'm trying to access and modify a variable of a thread in another thread in java, and I really don't know how to do this. ex : Runnable r1 = new Runnable() { int value = 10; public void run() { // random stuff } } Runnable r2 = new Runnable() { public void run() { // of course the bellow line will not work r1.value--; // I want here to be able to decrement the variable "value" of r1 } } Thread t1 = new Thread(r1); Thread t2 = new Thread(r2); t1.start(); t2.start(); thank you if you have any