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

 时间:2024-10-14 10:18:36

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如何加载项目中的图片
  • 热门搜索
    保护野生动物手抄报 抗击疫情手抄报内容 抗日战争手抄报 端午节的手抄报图片 欢乐中国年手抄报 我爱我班手抄报 我爱祖国的手抄报 消防安全知识手抄报 庆祝六一手抄报 小学一年级手抄报