• 线程详解


    线程详解
    1.我们都知道一个线程的启动,只有两种方式第一种是继承Thread方法,重写run方法,第二种是实现Runnable,叫个Thread执行
    2. 通过代码我们可以看到线程启动方法中,有start0(), 真正去启动一个线程,发现这个方法只是native修饰的方法,这边拓展一下什么是native修饰的方法

    public synchronized void start() {
            /**
             * This method is not invoked for the main method thread or "system"
             * group threads created/set up by the VM. Any new functionality added
             * to this method in the future may have to also be added to the VM.
             *
             * A zero status value corresponds to state "NEW".
             */
            if (threadStatus != 0)
                throw new IllegalThreadStateException();
    
            /* Notify the group that this thread is about to be started
             * so that it can be added to the group's list of threads
             * and the group's unstarted count can be decremented. */
            group.add(this);
    
            boolean started = false;
            try {
                start0();
                started = true;
            } finally {
                try {
                    if (!started) {
                        group.threadStartFailed(this);
                    }
                } catch (Throwable ignore) {
                    /* do nothing. If start0 threw a Throwable then
                      it will be passed up the call stack */
                }
            }
        }

    拓展:Native Method,查阅英文文献的解释,"A native method is a Java method whose implementation is provided by non-java code.",准确的说非java实现的方法,主要为了加载文件和动态链接库,可以直接操作系统属性
    3. 通过jni实现start0,内部初始化线程,最终会执行,vmSymbols::run_method_name():即"run";,也是java线程中run方法

    线程的生命周期:初始化(new) --> 可运行状态(start) --> 运行状态(run)& 子状态暂停和阻塞 --> 销亡

    具体业务:异步操作,FutureTask,里面有实现Runnable方法

    Unkonw Unkonw(你不知道一样东西,你也会不知道自己不知道这样东西)
  • 相关阅读:
    开悟人智慧一生,要学会忍辱才能精进!
    唯美MACD-完全版
    资本的力量 趋势的力量 规律的力量
    大趋势和小趋势的辩证关系(一)
    120日均线金叉250日均线是大牛市来临的重要信号
    趋势停顿与转折(三)
    趋势停顿与转折(二)
    趋势停顿与转折(一)
    MACD技术的高级应用--MACD与波浪
    SQL Server 2012:SQL Server体系结构——一个查询的生命周期(第2部分)
  • 原文地址:https://www.cnblogs.com/2014-1130/p/14278123.html
Copyright © 2020-2023  润新知