/**
1.创建线程的方法,通过实现接口
*/
public class MyThread implements Runnable{
//设置线程之间的共享的数据
private static int staticcount=1000;
//线程中的实现接口必须实现的接口
public void run(){
System.out.println("new thread");
}
public static void main(String[] args){
//创建线程
Thread th=new Thread(new MyThread());
//开启线程
th.run();
}
}
1.创建线程的方法,通过实现接口
*/
public class MyThread implements Runnable{
//设置线程之间的共享的数据
private static int staticcount=1000;
//线程中的实现接口必须实现的接口
public void run(){
System.out.println("new thread");
}
public static void main(String[] args){
//创建线程
Thread th=new Thread(new MyThread());
//开启线程
th.run();
}
}
本文介绍了一种使用Java创建线程的方法:通过实现Runnable接口。示例代码展示了如何定义一个实现了Runnable接口的类,并在其中指定线程的行为。此外,还介绍了如何创建并启动线程。
801

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



