线程的一些解释

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

 

https://blog.youkuaiyun.com/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值