1、启动eclipse,新建一个工程,在工程中新建一个类(具体看参考资料)
![eclipse(英文版)入门:[7]创建线程的两种方法](https://exp-picture.cdn.bcebos.com/65390a23beb9763e39f977656ad06de89b61b092.jpg)
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]创建线程的两种方法](https://exp-picture.cdn.bcebos.com/ba97ffd06de89a619b1e8d2045e8b004551bad92.jpg)
3、点击运行
![eclipse(英文版)入门:[7]创建线程的两种方法](https://exp-picture.cdn.bcebos.com/87645f93cee8b00475201dbc79260d9a300ea992.jpg)
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]创建线程的两种方法](https://exp-picture.cdn.bcebos.com/555acf0ff2260d9a1435db2a622abab84340a592.jpg)
5、点击运行
![eclipse(英文版)入门:[7]创建线程的两种方法](https://exp-picture.cdn.bcebos.com/304f0999e92abab86b7ba64d4814f1c594eea192.jpg)