eclipse(英文版)入门:[7]创建线程的两种方法

 时间:2026-04-22 22:32:11

1、启动eclipse,新建一个工程,在工程中新建一个类(具体看参考资料)

eclipse(英文版)入门:[7]创建线程的两种方法

2、【方法一】将以下代码复制到eclipse中:

class Xc extends Thread {

public void run() {

for(int i=0; i<20; i++) {

System.out.println("子函数");

}

}

}

public class test {

public static void main(String[] args) {

Xc xc = new Xc();

//xc.run();

xc.start();

for(int i=0; i<20; i++) {

System.out.println("主函数");

}

}

}

eclipse(英文版)入门:[7]创建线程的两种方法

3、点击运行

eclipse(英文版)入门:[7]创建线程的两种方法

4、【方法二】将以下代码复制到eclipse中:

public class test4 {

public static void main(String[] args) {

Thread xc1 = new Thread(new Xc41());

Thread xc2 = new Thread(new Xc42());

xc1.start();

xc2.start();

}

}

class Xc41 implements Runnable {

public void run() {

for(int i=0; i<100; i++) {

System.out.println("1线程" + i);

}

}

}

class Xc42 implements Runnable {

public void run() {

for(int i=0; i<100; i++) {

System.out.println("第二个线程正在被执行");

}

}

}

eclipse(英文版)入门:[7]创建线程的两种方法

5、点击运行

eclipse(英文版)入门:[7]创建线程的两种方法

  • 通过xampp安装mysql
  • 如何使用python语言中的方法获取字典中的值
  • 怎么在java中实现数据库表的简单增删改查?
  • IDEA代理抛出异常:1099端口占用
  • javafx的Image如何加载项目中的图片
  • 热门搜索
    墨菲定律是什么意思 舌头上有白苔怎么治 发票作废怎么处理 婴儿眼屎多是怎么回事 扬州今日生活 天猫如何开店 如何删除文件 ps是什么意思 路由器限速怎么设置 北漂生活