Thread-Specific Storage
来源:互联网 发布:淘宝宣传文案怎么写 编辑:程序博客网 时间:2024/05/22 10:20
public class TSLog {
private PrintWriter writer = null;
public TSLog(String filename){
try {
writer = new PrintWriter(new FileWriter(filename));
} catch (IOException e) {
e.printStackTrace();
}
}
public void println(String s){
writer.println(s);
}
public void close(){
writer.println("=== END OF LOG ===");
writer.close();
}
}
public class Log {
private static final ThreadLocal tsLogCollection = new ThreadLocal();
public static void println(String s){
getTSLog().println(s);
}
public static void close(){
getTSLog().close();
}
private static TSLog getTSLog(){
TSLog tsLog = (TSLog) tsLogCollection.get();
if(tsLog == null){
tsLog = new TSLog(Thread.currentThread().getName()+" - log.txt");
tsLogCollection.set(tsLog);
}
return tsLog;
}
}
public class ClientThread extends Thread {
public ClientThread(String name){
super(name);
}
public void run(){
System.out.println(getName()+" BEGIN");
for(int i=0;i<10;i++){
Log.println("i = " + i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.close();
System.out.println(getName() + " END");
}
}
- Thread-Specific Storage
- Thread-Specific Storage
- Thread-Specific Storage 模式
- Thread Specific Storage
- Thread-Specific Storage Pattern
- 第十一章 Thread-Specific Storage
- 利用Thread-Specific Storage撰寫一個HibernateUtil
- 利用Thread-Specific Storage撰寫一個HibernateUtil
- 线程特有存储模式(Thread Specific Storage)
- 线程局部存储 Thread Local Storage 线程特定数据 Thread-Specific Data
- 多线程设计模式——Thread Specific Storage(线程特有存储)模式
- Thread-specific data
- Thread-specific data
- 线程私有数据thread-specific
- python thread wait until specific thread complete
- Thread-Local Storage
- TLS (Thread local storage)
- Thread-Local Storage(TLS)
- QT显示机制
- 【转】Google 推出中文版《浏览器和网络世界20大须知》
- strcpy strncpy strlcpy
- B/S C/S 的优缺点以及适应的场合
- ADFS
- Thread-Specific Storage
- XML基本语法
- iphone 使用自定义字体
- iphone 使用自定义字体
- Android开机广播和关机广播
- 统计一个文件中特定字符的个数
- 文件描述符
- cookie & session机制
- 无心之错 过犹不及 ssh