⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例子十二.txt

📁 Java大学实用教程 耿祥义编著 课件 PPT
💻 TXT
字号:
class Daemon  implements Runnable
{
    Thread A,B;
    Daemon()
    {
       A=new Thread(this);
       B=new Thread(this);
    }
   public void run()
    {
       if(Thread.currentThread()==A)
         {
            for(int i=0;i<8;i++)
             {
                 System.out.println("i="+i) ;
                 try 
                 {
                   Thread.sleep(1000);    
                 }
                 catch(InterruptedException e)
                 {
                 }
             } 
         }
       else if(Thread.currentThread()==B)
         { 
            while(true)
            {
               System.out.println("线程B是守护线程 "); 
               try 
               {
                   Thread.sleep(1000);    
               }
                   catch(InterruptedException e)
               {
               }
            }
         }
      
    }    
}
class Example
{
    public static void main(String args[ ])
    {
        Daemon  a=new Daemon ();
        a.A.start();
        a.B.setDaemon(true);
        a.B.start();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -