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

📄 testthread.java

📁 本书是一本为Java学习者在基础内容学习结束后进行课程设计时提供参考的指导书
💻 JAVA
字号:
package apibook.c2.s3;public class TestThread {  public static void main(String[] args) {    Thread r=null;    for (int i=0;i<5 ;i++ ) {      r=new ct(i);      r.start();    }  }}class ct extends Thread{  private int k;  public ct(int j){    k=j;  }  public void run(){    for (int i=0;i<100;i++ ) {      synchronized(System.out){          System.out.println(Thread.currentThread().getName());          System.out.println(Thread.activeCount());          this.setPriority(3);          //System.out.println(Thread.currentThread().getPriority());      }          try {            Thread t=null;            for(int n=0;n<3;n++){              t=new ctt(k,n);              t.setPriority(5);              t.join();              t.start();            }            //this.wait();            //this.notifyAll();            this.sleep(50);          }          catch (Exception ex) {          }    }  }}class ctt extends Thread{  private int k,m;  public ctt(int l,int j){    k=l;    m=j;  }  public void run(){    for (int i=0;i<100 ;i++ ) {      synchronized(System.out){          System.out.println("child Thread:"+k+"-"+m);      }          try {            //this.wait();            //this.notifyAll();            this.sleep(50);          }          catch (Exception ex) {          }    }  }}

⌨️ 快捷键说明

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