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

📄 threadterminate.java

📁 用java编写的有关线程测试的程序
💻 JAVA
字号:
public class ThreadTerminate {
    public static void main(String args[ ]) throws Exception{
	
		int i=0;
		Hello h = new Hello();
	
		Thread t = new Thread( h);
		t.setPriority(Thread.MAX_PRIORITY);
		t.start( );
	
		System.out.println("Please stop saying Hello and say good morning!");
		h.stopRunning();
		
		while( i<5){
		    
		   	System.out.println("Good Morning"+i++);
		   	
		}
	
  	}
}


class Hello implements Runnable{
   
    int i = 0;
    private boolean  timeToQuit = false;
    
    public void run( ){
		while(!timeToQuit){  
	 	
			System.out.println(" Hello"+i++);
			try{
			   if (i%2 == 0 )
			       Thread.sleep(10);

			 } catch(Exception e){ }
		
		}
    }
    
    public void stopRunning( ){
		timeToQuit = true ;
    }
}

⌨️ 快捷键说明

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