使用java中的Thread类来创建线程。有两种方法可以创建线程:
1. 继承Thread类,重写run()方法
```java
public class MyThread extends Thread {
public void run() {
// 线程执行的代码
}
}
// 创建线程并启动
MyThread thread = new MyThread();
t();
```
2. 实现Runnable接口,传入Thread类构造方法中
```java
public class MyRunnable implements Runnable {
public void run() {
// 线程执行的代码
}
}
// 创建Runnable对象
MyRunnable runnable = new MyRunnable();
// 创建线程并启动
Thread thread = new Thread(runnable);
t();
```