Home > Back-end > Could you tell me how to modify as required, this
Could you tell me how to modify as required, this
Time:09-21
As shown in figure
CodePudding user response:
//thread 1 Public void the run () { Synchronized (SyncThreads1. Class) {//to lock the same object, rather than the thread lock the object itself, because thread 1 and thread 2 object is not visible and do not affect each other, to lock the common resource will happen influence X=y=0; System. The out. Println (x); } }
//thread 2 Public void the run () { Synchronized (SyncThreads1. Class) { X=y=1; System. The out. Println (x); } }