I have the following class:
public class MyTestThreadStatic {
private static int myNum;
private MyTestThreadStatic () { // private constructor
}
public static void setMyNum(int val) {
myNum = val;
}
public static int addOne() {
return myNum + 1;
}
.....
code block {
//thread 1 at t0
... some code to create a thread to call static class
System.out.println("val=" + MyTestThreadStatic.addOne());
... some other code to create a thread to call static class
//thread 2 at t0
MyTestThreadStatic.setMyNum(200);
System.out.println("val=" + MyTestThreadStatic.addOne());
}
//stack created?
At t0 (time 0), two threads call function addOne. Will this work as expected? Will it work because two stacks were created? I would want to test this and looked at Thread and Runnable, but I am not seeing a way since neither have static methods and require object instance.