Skip to content

Commit 606972f

Browse files
committed
rename project: TransmittableThreadLocal(TTL) alibaba#59
- update code and doc: concept multi-thread context(MTC) => TTL - package mtc => ttl - update word 'context' to 'TTL value'
1 parent 40d08ef commit 606972f

64 files changed

Lines changed: 1652 additions & 1647 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README-EN.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
multi-thread context(MTC)
1+
Transmittable ThreadLocal(TTL)
22
=====================================
33

44
[![Build Status](https://travis-ci.org/alibaba/multi-thread-context.svg?branch=master)](https://travis-ci.org/alibaba/multi-thread-context)
@@ -16,20 +16,20 @@ multi-thread context(MTC)
1616
:wrench: Functions
1717
----------------------------
1818

19-
:point_right: Transmit multi-thread context, even using thread cached components like thread pool.
19+
:point_right: Transmit `ThreadLocal` value between threads, even using thread cached components like thread pool.
2020

2121
Class [`java.lang.InheritableThreadLocal`](http://docs.oracle.com/javase/6/docs/api/java/lang/InheritableThreadLocal.html) in `JDK`
22-
can transmit context to child thread from parent thread.
22+
can transmit value to child thread from parent thread.
2323

24-
But when use thread pool, thread is cached up and used repeatedly. Transmitting context from parent thread to child thread has no meaning.
25-
Application need transmit context from the time task is created to the time task is executed.
24+
But when use thread pool, thread is cached up and used repeatedly. Transmitting value from parent thread to child thread has no meaning.
25+
Application need transmit value from the time task is created to the time task is executed.
2626

2727
If you have problem or question, please [submit Issue](https://github.com/alibaba/multi-thread-context/issues) or play [fork](https://github.com/alibaba/multi-thread-context/fork) and pull request dance.
2828

2929
:art: Requirements
3030
----------------------------
3131

32-
The Requirements listed below is also why I sort out `MTC` in my work.
32+
The Requirements listed below is also why I sort out `TTL` in my work.
3333

3434
* Application container or high layer framework transmit information to low layer sdk.
3535
* Transmit context to logging without application code aware.
@@ -42,7 +42,7 @@ The Requirements listed below is also why I sort out `MTC` in my work.
4242

4343
```java
4444
// set in parent thread
45-
MtContextThreadLocal<String> parent = new MtContextThreadLocal<String>();
45+
TransmittableThreadLocal<String> parent = new TransmittableThreadLocal<String>();
4646
parent.set("value-set-in-parent");
4747

4848
// =====================================================
@@ -53,29 +53,29 @@ String value = parent.get();
5353

5454
This is the function of class [`java.lang.InheritableThreadLocal`](http://docs.oracle.com/javase/6/docs/api/java/lang/InheritableThreadLocal.html), should use class [`java.lang.InheritableThreadLocal`](http://docs.oracle.com/javase/6/docs/api/java/lang/InheritableThreadLocal.html) instead.
5555

56-
But when use thread pool, thread is cached up and used repeatedly. Transmitting context from parent thread to child thread has no meaning.
57-
Application need transmit context from the time task is created to the point task is executed.
56+
But when use thread pool, thread is cached up and used repeatedly. Transmitting value from parent thread to child thread has no meaning.
57+
Application need transmit value from the time task is created to the point task is executed.
5858

5959
The solution is below usage.
6060

61-
2. Transmit context even using thread pool
61+
2. Transmit value even using thread pool
6262
----------------------------
6363

6464
### 2.1 Decorate `Runnable` and `Callable`
6565

66-
Decorate input `Runnable` and `Callable` by [`com.alibaba.mtc.MtContextRunnable`](src/main/java/com/alibaba/mtc/MtContextRunnable.java)
67-
and [`com.alibaba.mtc.MtContextCallable`](src/main/java/com/alibaba/mtc/MtContextCallable.java).
66+
Decorate input `Runnable` and `Callable` by [`com.alibaba.ttl.TtlRunnable`](/src/main/java/com/alibaba/ttl/TtlRunnable.java)
67+
and [`com.alibaba.ttl.TtlCallable`](src/main/java/com/alibaba/ttl/TtlCallable.java).
6868

6969
Sample code:
7070

7171
```java
72-
MtContextThreadLocal<String> parent = new MtContextThreadLocal<String>();
72+
TransmittableThreadLocal<String> parent = new TransmittableThreadLocal<String>();
7373
parent.set("value-set-in-parent");
7474

7575
Runnable task = new Task("1");
76-
// extra work, create decorated mtContextRunnable object
77-
Runnable mtContextRunnable = MtContextRunnable.get(task);
78-
executorService.submit(mtContextRunnable);
76+
// extra work, create decorated ttlRunnable object
77+
Runnable ttlRunnable = TtlRunnable.get(task);
78+
executorService.submit(ttlRunnable);
7979

8080
// =====================================================
8181

@@ -86,13 +86,13 @@ String value = parent.get();
8686
above code show how to dealing with `Runnable`, `Callable` is similar:
8787

8888
```java
89-
MtContextThreadLocal<String> parent = new MtContextThreadLocal<String>();
89+
TransmittableThreadLocal<String> parent = new TransmittableThreadLocal<String>();
9090
parent.set("value-set-in-parent");
9191

9292
Callable call = new Call("1");
93-
// extra work, create decorated mtContextCallable object
94-
Callable mtContextCallable = MtContextCallable.get(call);
95-
executorService.submit(mtContextCallable);
93+
// extra work, create decorated ttlCallable object
94+
Callable ttlCallable = TtlCallable.get(call);
95+
executorService.submit(ttlCallable);
9696

9797
// =====================================================
9898

@@ -105,23 +105,23 @@ String value = parent.get();
105105
Eliminating the work of `Runnable` and `Callable` Decoration every time it is submitted to thread pool. This work can completed in the thread pool.
106106

107107
Use util class
108-
[`com.alibaba.mtc.threadpool.MtContextExecutors`](src/main/java/com/alibaba/mtc/threadpool/MtContextExecutors.java)
108+
[`com.alibaba.ttl.threadpool.TtlExecutors`](src/main/java/com/alibaba/ttl/threadpool/TtlExecutors.java)
109109
to decorate thread pool.
110110

111-
Util class `com.alibaba.mtc.threadpool.MtContextExecutors` has below methods:
111+
Util class `com.alibaba.ttl.threadpool.TtlExecutors` has below methods:
112112

113-
* `getMtcExecutor`: decorate interface `Executor`
114-
* `getMtcExecutorService`: decorate interface `ExecutorService`
113+
* `getTtlExecutor`: decorate interface `Executor`
114+
* `getTtlExecutorService`: decorate interface `ExecutorService`
115115
* `ScheduledExecutorService`: decorate interface `ScheduledExecutorService`
116116

117117
Sample code:
118118

119119
```java
120120
ExecutorService executorService = ...
121121
// extra work, create decorated executorService object
122-
executorService = MtContextExecutors.getMtcExecutorService(executorService);
122+
executorService = TtlExecutors.getTtlExecutorService(executorService);
123123

124-
MtContextThreadLocal<String> parent = new MtContextThreadLocal<String>();
124+
TransmittableThreadLocal<String> parent = new TransmittableThreadLocal<String>();
125125
parent.set("value-set-in-parent");
126126

127127
Runnable task = new Task("1");
@@ -137,7 +137,7 @@ String value = parent.get();
137137

138138
### 2.3. Use Java Agent to decorate thread pool implementation class
139139

140-
In this usage, `MtContext` transmission is transparent\(no decoration operation\).
140+
In this usage, transmission is transparent\(no decoration operation\).
141141

142142
Sample code:
143143

@@ -155,31 +155,31 @@ executorService.submit(call);
155155
String value = parent.get();
156156
```
157157

158-
See demo [`AgentDemo.java`](src/test/java/com/alibaba/mtc/threadpool/agent/AgentDemo.java).
158+
See demo [`AgentDemo.java`](src/test/java/com/alibaba/ttl/threadpool/agent/AgentDemo.java).
159159

160160
Agent decorate 2 thread pool implementation classes
161-
\(implementation code [`MtContextTransformer.java`](src/main/java/com/alibaba/mtc/threadpool/agent/MtContextTransformer.java)\):
161+
\(implementation code [`TtlTransformer.java`](src/main/java/com/alibaba/ttl/threadpool/agent/TtlTransformer.java)\):
162162

163163
- `java.util.concurrent.ThreadPoolExecutor`
164164
- `java.util.concurrent.ScheduledThreadPoolExecutor`
165165

166166
Add start options on Java command:
167167

168-
- `-Xbootclasspath/a:/path/to/multithread.context-x.y.z.jar:/path/to/javassist-3.12.1.GA.jar`
169-
- `-javaagent:/path/to/multithread.context-x.y.z.jar`
168+
- `-Xbootclasspath/a:/path/to/transmittable-thread-local-2.x.x.jar`
169+
- `-javaagent:/path/to/transmittable-thread-local-2.x.x.jar`
170170

171171
**NOTE**
172172

173-
* Agent modify the jdk classes, add code refer to the class of `MTC`, so the jar of `MTC Agent` should add to `bootclasspath`.
174-
* `MTC Agent` modify the class by `javassist`, so the Jar of `javassist` should add to `bootclasspath` too.
173+
* Agent modify the jdk classes, add code refer to the class of `TTL`, so the jar of `TTL Agent` should add to `bootclasspath`.
174+
* `TTL Agent` modify the class by `javassist`, so the Jar of `javassist` should add to `bootclasspath` too.
175175

176176
Java command example:
177177

178178
```bash
179-
java -Xbootclasspath/a:dependency/javassist-3.12.1.GA.jar:multithread.context-1.0.0.jar \
180-
-javaagent:multithread.context-0.9.0-SNAPSHOT.jar \
179+
java -Xbootclasspath/a:transmittable-thread-local-2.0.0.jar \
180+
-javaagent:transmittable-thread-local-2.0.0.jar \
181181
-cp classes \
182-
com.alibaba.mtc.threadpool.agent.AgentDemo
182+
com.alibaba.ttl.threadpool.agent.demo.AgentDemo
183183
```
184184

185185
Run the script [`run-agent-demo.sh`](run-agent-demo.sh)
@@ -196,12 +196,12 @@ The current version Java API documentation: <http://alibaba.github.io/multi-thre
196196
```xml
197197
<dependency>
198198
<groupId>com.alibaba</groupId>
199-
<artifactId>multithread.context</artifactId>
200-
<version>1.2.1</version>
199+
<artifactId>transmittable-thread-local</artifactId>
200+
<version>2.0.0</version>
201201
</dependency>
202202
```
203203

204-
Check available version at [search.maven.org](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.alibaba%22%20AND%20a%3A%22multithread.context%22).
204+
Check available version at [search.maven.org](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.alibaba%22%20AND%20a%3A%22transmittable-thread-local%22).
205205

206206
:books: Related resources
207207
=====================================

0 commit comments

Comments
 (0)