Hello. I can not explain for myself the principle of the organization and work of threads in Java. I will try to briefly explain the essence of the problem. There is a class MyClass :
public MyClass { public void method1(int n) { int c = method2(n); // Ещё что-то } public int method2(int n) { // что-то делает } } I create a single instance of this class called myObject . I create Runnable , into which I pass a link to my object and in run () I perform the following actions:
public void run() { while (true) { myobject .method2(someInt); } } Then I run several threads with this Runnable . Please note that the methods are not synchronized, nothing is synchronized at all. The first thread enters method1 and calculates C = C1, then it is pushed out, after that the second stream enters method1, counts C = C2 and is superseded. After that, the first thread wakes up and continues with the execution of method 1, what will be the value of C for the continuing flow # 1?