• Thread和ThreadGroup


    Thread和ThreadGroup

    学习了:https://www.cnblogs.com/yiwangzhibujian/p/6212104.html  这个里面有Thread的基本内容;

    http://blog.csdn.net/a352193394/article/details/39323427 这个讲解了ThreadGroup

    https://www.cnblogs.com/yy2011/archive/2011/05/05/2037564.html 这个比较了ThreadGroup与Executor

    Thread比如属于一个ThreadGroup,

    源码:

            Thread parent = currentThread();
            SecurityManager security = System.getSecurityManager();
            if (g == null) { // 这个就是ThreadGroup
                /* Determine if it's an applet or not */
    
                /* If there is a security manager, ask the security manager
                   what to do. */
                if (security != null) {
                    g = security.getThreadGroup();
                }
    
                /* If the security doesn't have a strong opinion of the matter
                   use the parent thread group. */
                if (g == null) {
                    g = parent.getThreadGroup();
                }
            }

    Thread.setUncaughtExceptionHandler的意义在于不能修改原线程的情况下,为其增加一个错误处理器。

    package com.stono.thread2;
    
    import java.lang.Thread.UncaughtExceptionHandler;
    
    // UnCaughtException意义在于不能对原线程修改的情况下,为其增加一个错误处理器。
    public class ThreadUncaughtException {
        public static void main(String[] args) {
            Thread t1 = new Thread(new Runnable() {
                public void run() {
                    int a = 1/0;
                }
            });
            t1.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    System.out.println("线程:"+t.getName()+"出现异常,异常信息:"+e);
                    e.printStackTrace();
                }
            });
            t1.start();
        }
    }

    ThreadGroup.enumerate(list)方法把ThreadGroup中的线程拷贝到新的List中;

     在ThreadGroup讲解过程中,一个runnable对象构建了多个线程,这个需要注意一下,TODO

  • 相关阅读:
    一直在维护一些项目,其实 这些项目也没有太大的需求,
    iis 7 url 重写
    xmlapp 如何配置
    [转载]什么是native compiler?什么是cross compiler?
    CDC工具
    EDA工具介绍(数字设计)
    让FPGA初学者头疼的各种仿真【转载】
    [SOF] Pointers, smart pointers or shared pointers?
    GNU的工具gmake and make
    mealy machine和moore machine
  • 原文地址:https://www.cnblogs.com/stono/p/8370494.html
Copyright © 2020-2023  润新知