// implement file: MyThread.java
//
package org.lxh.demo16.thd;
/**
* 定义一个线程类
* @author Owner
*
*/
class MyThd extends Thread {
private String name;
public MyThd(String name) {
this.name = name;
}
public void run() {
for(int i = 0; i < 100; i++) {
System.out.println(name + "run, i=" + i + "-->" + Thread.currentThread().getName());
}
}
}
/**
* 这个类是演示使用线程的
* @author Owner
*
*/
public class MyThread extends Thread {
public MyThread() {
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThd thd1 = new MyThd("Thd A ");
MyThd thd2 = new MyThd("Thd B ");
//error
//thd1.run();
//thd2.run();
//start thread
thd1.start();
thd2.start();
new MyThd("Test thread").start();
}
}
Java入门, 线程
最新推荐文章于 2024-09-24 10:50:41 发布