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

📄 twothread.java

📁 介绍有关java的资料 课件 相当一本书籍 里面都是很基础的知识
💻 JAVA
字号:
class twothread implements Runnable {  twothread() {    Thread t1 =Thread.currentThread();    t1.setName("The first main thread");    System.out.println("The running thread:" + t1);    Thread t2 = new Thread(this,"the second thread");    System.out.println("creat another thread");    t2.start();    try {      System.out.println("first thread will sleep");      //Thread.sleep(4000);      t1.sleep(4000);     } catch (InterruptedException e) {       System.out.println("first thread has wrong");     }     System.out.println("first thread exit");  }  public void run() {     try { for (int i=0;i<5;i++) {        System.out.println("Sleep time for thread 2:"+i);        Thread.sleep(1000);}      } catch (InterruptedException e) {        System.out.println("thread has wrong");      }      System.out.println("second thread exit");  }  public static void main(String args[]) {     new twothread();  }}

⌨️ 快捷键说明

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