线程:Java中1个线程需要占用1M的栈空间,对cpu影响较大,所以需要cpu进行线程调度;
线程启动方法:
一,继承Thread.currentThread().start() /run()
二,实现Runnable接口:重写run方法
run? 线程调度方法,让cpu调度;
示例代码:
public static void main(String[] args) { System.out.println("主线程运行开始"+" 线程名:"+Thread.currentThread().getName()); Thread thread = new Thread(); thread.start();System.out.println(" 线程名:" +thread.getName()); thread.run(); System.out.println(" 线程名:" +thread.getName()); //接口实现Runnable ThreadStudy threadStudy = new ThreadStudy(); threadStudy.run(); System.out.println("主线程运行"+" 线程名:" +Thread.currentThread().getName()); //继承thread MyThread myThread = new MyThread(); myThread.run(); System.out.println("继承线程类ÿ