加不加synchronized都属于override

解决方案 »

  1.   

    晕,synchronized和覆盖是没有关系的
    你这个写的怎么都不可能同步,因为你有2个对象,就是两把锁,线程分别拥有各自的对象,当然不能同步
    修该一下吧
    public class testThread extends Thread
    {
    public  void run() {
      
       testThread.todo();
        
    }private synchronized static void todo() {
      for(int i=0;i<999;i++) {
        System.out.println(i);
      }
    }
    public static void main(String[] args) {
      testThread t1=new testThread();
      testThread t2=new testThread();
      t1.start();
      t2.start();
    }
    }
      

  2.   

    楼上说得没错,这样写法毫无意义,除非你的类是singleton的,或者方法是static的,这样保证所有应用是在访问同一个实例或者同一个方法,这样同步才会有作用