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

📄 forsome.java

📁 这一些程序都是实验之用
💻 JAVA
字号:
package occupycpu;
public class ForSome extends Thread{
	private static StringBuffer log =new StringBuffer();
	private static int count =0;
	public void run(){
	/*	for(int i=0;i<20;i++)
		 {
		 	log.append(currentThread().getName()+":"+i+" ");
		 	if(++count%10==0)log.append("\n");
		 	
		 }*/
	/*for(int i=0;i<20;i++)
	   {
	   	 log.append(currentThread().getName()+":"+i+" ");
	   	 if(++count%10==0)log.append("\n");
	   	 try{
	   	 		   	 	 sleep(100);
	   	 	  }catch(InterruptedException e){throw new RuntimeException(e);}
	   }	 
		}*/
			/*try{
			sleep(60000);
			System.out.println("sleep end");
			}catch(InterruptedException e){System.out.println("sleep interrupted");}
			System.out.println("end");
			}*/
			for(int a=0;a<20;a++)
			 {
			 	log.append(currentThread().getName()+":"+a+" ");
			 	if(++count%10==0)log.append("\n");
			 	yield();
			 }
			}
			
		public static void main(String arg[])throws Exception{
			 ForSome forsome1=new ForSome();
			 ForSome forsome2=new ForSome();
			 forsome1.setName("r1");
			 forsome2.setName("r2");
			 forsome1.start();
			 forsome2.start();
			 while(forsome1.isAlive()||forsome2.isAlive())
			  {Thread.sleep(1000);}
			  System.out.println(log);
			  
		}
	
	}

⌨️ 快捷键说明

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