zoukankan      html  css  js  c++  java
  • Thread 与 ThreadLocal

    @Test
    public void testThread() {
    Thread thread = Thread.currentThread();
    System.out.println("thread:" + thread);
    //当前线程 id
    System.out.println("threadId:" + thread.getId());
    //当前线程名称
    System.out.println("threadName:" + thread.getName());
    //当前线程状态
    System.out.println("threadState:" + thread.getState());
    //当前线程优先级
    System.out.println("threadPriority:" + thread.getPriority());
    //当前线程组名称
    System.out.println("threadThreadGroup,Name:" + thread.getThreadGroup().getName());
    //当前线程组父类
    System.out.println("threadThreadGroup,parent:" + thread.getThreadGroup().getParent());
    //当前线程组的最高优先级别
    System.out.println("threadThreadGroup,MaxPriority:" + thread.getThreadGroup().getMaxPriority());
    System.out.println("threadStackTrace:" + thread.getStackTrace());
    System.out.println("ContextClassLoader:" + thread.getContextClassLoader());
    }


    @Test
    public void testThreadLocal() {
    ThreadLocal<Object> threadLocal = new ThreadLocal<>();
    //默认为 null,初始值为 null
    System.out.println(threadLocal.get());
    //给当前线程设置值
    threadLocal.set("aaa");
    System.out.println(threadLocal.get());
    threadLocal.set("bbb");
    System.out.println(threadLocal.get());
    //清空线程值
    threadLocal.remove();
    }
  • 相关阅读:
    SQL 列转行
    SQL 行转列
    ActionScript 3.0 学习笔记三
    VS 2010 添加扩展工具
    VS 2010 启动慢解决办法
    [SQL Server]游标示例
    SQL Server 2005 express TCP/IP 不能连接的配置
    FCKeditor.Net v2.6.3 上传图片的配置及注意事项
    HTTP/1.1 403 Forbidden
    存储过程中常使用的逻辑控制语句
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/11906506.html
Copyright © 2011-2022 走看看