Threading and synchronized methods

前端 未结 3 2081
甜味超标
甜味超标 2021-01-21 12:24

I have the following code:

public class MyThread extends Thread {
    private int i;
    public static int sum=0;
    public MyThread(int k){
      i=k;
    }


         


        
3条回答
  •  青春惊慌失措
    2021-01-21 13:18

    The synchronization on methods only holds for invocations of the same object. You are creating two different objects (the two threads).

提交回复
热议问题