在Java中实现多线程并发可以使用Thread类或Executor框架。
以下是使用Thread类的示例:
public class MyThread extends Thread {
@Override
public void run() {
// 执行线程任务
}
}
public class Main {
public static void main(String[] args) {
MyThread thread1 = new MyThread();
MyThread thread2 = new MyThread();
// 启动线程
thread1.start();
thread2.start();
}
}