zoukankan      html  css  js  c++  java
  • 线程详解

    线程详解
    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(你不知道一样东西,你也会不知道自己不知道这样东西)
  • 相关阅读:
    GAN阶段性小结(损失函数、收敛性分析、训练技巧、应用“高分辨率、domain2domain”、研究方向)
    MMD :maximum mean discrepancy
    Chinese-BERT-wwm
    VGG16学习笔记
    jupyter notebook使用技巧--命令行模式以及在Markdown模式使用的操作(4)
    不同领域公开数据集下载
    数据挖掘竞赛,算法刷题网址汇总
    在keras下实现多个模型的融合
    问题集合
    开源测试数据集合
  • 原文地址:https://www.cnblogs.com/2014-1130/p/14278123.html
Copyright © 2011-2022 走看看