ITeye博客

牛牛

niumd · 共 2 篇文章

ThreadLocal示例

本文借花献佛,引用Tim Cull的博文“SimpleDateFormat: Performance Pig”介绍下ThreadLocal的简单使用,同时也对SimpleDateFormat的使用有个深入的了解。 Tim Cull 写道 Just yesterday I came across this problem “in the wild” for the third time in my career so far: an application with performance problems creating tons of java.text.SimpleDateFormat…

2010-09-07 16:27 · java · 评论(50)

深入浅出ThreadLocal

一、ThreadLocal概述 学习JDK中的类,首先看下JDK API对此类的描述,描述如下: JDK API 写道 该类提供了线程局部 (thread-local) 变量。这些变量不同于它们的普通对应物,因为访问某个变量(通过其 get 或 set 方法)的每个线程都有自己的局部变量,它独立于变量的初始化副本。ThreadLocal 实例通常是类中的 private static 字段,它们希望将状态与某一个线程(例如,用户 ID 或事务 ID)相关联。 API表达了下面几种观点: 1、ThreadLocal不是线程,是线程的一个变量,你可以先简单理解为线程类的属性变量。 2、Threa…

2010-09-07 14:16 · java · 评论(22)