这里的self标识符声明一个线程局部变量time。
Here the self identifier declares a thread local variable time.
线程局部变量高效地为每个使用它的线程提供单独的线程局部变量值的副本。
A thread-local variable effectively provides a separate copy of its value for each thread that USES it.
要创建一个线程局部变量,请实例化类ThreadLocal的一个对象。
To create a thread-local variable, you instantiate an object of class ThreadLocal.
相反地,人们通过给Thread添加一个实例变量(该变量用于保存当前线程的从线程局部变量到它的值的映射的HashMap)来修改thread类以支持ThreadLocal。
Instead, the thread class was modified to support ThreadLocal by adding an instance variable to thread that holds a HashMap mapping thread-local variables to their values for the current thread.
它包含了栈帧和局部变量,但与真正的线程不同的是它无法执行。
It includes stack frames and local variables, but unlike a true thread it is not executable.
现在,我们在局部变量sum上创造了一场数据竞争,因为多个线程可能同时希望更新它。
Now, we would have created a data race on the local variable sum, because multiple threads might want to update it simultaneously.
可以在程序注册表中、每一个线程堆栈中的(基于堆栈的)局部变量中以及静态变量中找到根。
Roots can be found in program registers, in local (stack-based) variables in each thread's stack, and in static variables.
应用程序中的每个线程都有自己的局部变量time,因此每个应用程序线程可以跟踪自己的时间。
Each thread in the application will have its own local variable time, thus enabling each application thread to track its time.
静态局部变量的指针不是线程安全的?
应用程序的根包含全局对象指针、静态对象指针、线程堆栈中的局部变量和引用对象参数以及CPU寄存器。
An application's roots include global and static object Pointers, local variables and reference object parameters on a thread's stack, and CPU registers.
换句话说,任何局部变量是在新线程的创造过程的定义。
In other words any local variables are redefined in the process of new thread's creation.
换句话说,任何局部变量是在新线程的创造过程的定义。
In other words any local variables are redefined in the process of new thread's creation.
应用推荐