线程的一些解释

https://www.cnblogs.com/wxd0108/p/5479442.html

https://blog.csdn.net/lai_li/article/details/53070141?locationNum=13&fps=1

package thread.test;

public class TestOne {
    public static void main(String[] args) {

        //模拟多线程
    /*    for (int i = 0; i < 100; i++) {
                new Thread(){
                    public void  run() {
                        //code
                    };
                }.start();
            }
        
        //java8才支持
        Runnable r = () -> {
            
        };
        Thread thread = new Thread(r);
        thread.start();
        new Thread(r).start();*/
        
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        //java中启动线程有两种方式 Thread类,实现Runnable接口
        
        
        //start 方法
        //该方法启动线程的同时也创建了一个线程,真正实现了多线程。   start方法使线程处于就绪状态,得到cpu的空闲时间执行线程。
        //不必等待run方法执行完后启动另外一个线程,run方式是线程执行的内容,run()方法结束,线程就终止了。
        
        
        //run() 方法
        //Runnable 的run方法并没有创建新的线程,只有一个主线程,必须等待run方法执行完毕后才会执行后面的code。
        
//        for (int i = 0; i < 100; i++) {
//            System.out.println("i------>>>"+i); 
            Thread t =  new Thread(){
                public void run() {
                    method();
                }
            };
       t.run(); //t.start(); System.out.println(
"1"); // } } public static void method(){ System.out.println("2"); } }
原文地址:https://www.cnblogs.com/lxh520/p/8882711.html