全局变量就是不管你在哪里,都能够直接引用的变量,还不用担心各种问题.每个语言都有自己的全局变量,我想! 一般地,面向过程的语言当中,可能就是一个声明在最前面的变量,后面的代码直接引用,就成了全局变量!(最经典的C就是这样的) 如:js 中: var a = "hello,a!"; alert(a); function fn1() { var b = "hello, b!" alert("global var a: " + a); } fn1();
ThreadLocal 先来看看ThreadLocal的注释: This class provides** thread-local variables**. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the
概述 相信读者在网上也看了很多关于ThreadLocal的资料,很多博客都这样说:ThreadLocal为解决多线程程序的并发问题提供了一种新的思路:ThreadLocal的目的是为了解决多线程访问资源时的共享问题.如果你也这样认为的,那现在给你10秒钟,清空之前对ThreadLocal的错误的认知! 看看JDK中的源码是怎么写的: This class provides thread-local variables. These variables differ from their norm