package duoxiancheng;
class The extends Thread//继承Thread创建多线程
{
String s;
The(String s)//此构造函数是为了自定义线程名称
{
this.s=s;
}
public void run()//覆盖run方法
{
for(int i=0;i<=10;i++)
{
System.out.println(s+"...run");
}
}
}
public class TheadDemo1 {
public static void main(String [] args)
{
The t1=new The("one");
The t2=new The("two");
t1.start();
t2.start();
}
}
(多线程)TheadDemo1
本文详细介绍了如何使用Java的Thread类实现多线程并发操作,通过自定义线程类来实现特定任务的并行执行,展示了start()方法启动线程及run()方法执行线程任务的过程。

被折叠的 条评论
为什么被折叠?



