1
 i have an animation program using threads and applet.

当我从 appletviewer 程序中的小程序菜单调用停止选项时工作正常,但是当我按下重新启动时,它的工作出现了一些异常。在第 34 行调用重新启动时,线程不会退出 while 循环

   class saver
    {
    .


     .
        public void run()
        {
        System.out.println("run "+Thread.currentThread().getName());
         func();
        System.out.println("out of synchronized block");
        }
        synchronized public void func()
        {
        int i;
        while(running)
        {
        for(i=0;i<4;i++)
        {
        gap[i]+=10;
        if(gap[i]==360)
        gap[i]=0;
        System.out.println(Thread.currentThread().getName());
        calc(gap[i],400,i%2==0?(byte)1:(byte)-1);
        yb[i]=(int)(y)+yc;
        xb[i]=(int)(x)+xc;
      }
        repaint();
         try                   
          {                 
           Thread.sleep(1000);          
         }              
        catch(Exception e)
        {}
         }
         System.out.println("out of while in synchronized block");//not being printed
        } 
4

0 回答 0