创建并开启线程
一个类继承Thread类或者实现Runnable大智慧股票交易大智慧股票交易接口,接口,大智慧股票交易接口,接口都可以创建一个线程。如下示例:继承Thread方法,实现Runnable大智慧股票交易大智慧股票交易接口,接口,大智慧股票交易接口,接口:
public class ThreadTest {
public static void main(String[] args) {
MyThread myThread = new MyThread();
myThread.start();
MyThread myThread1 = new MyThread();
Thread thread1 = new Thread(myThread1);
thread1.start();
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.start();
}
static class MyThread extends Thread {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
System.out.println('Thread.currentThread().getName() = ' + Thread.currentThread().getName() + ' ' + this.isAlive());
}
}
static class MyRunnable implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
}
根据源码可知target对象就是传入的Runnable的实现类对象。
文章为作者独立观点,不代表股票交易接口观点