Download Jar. Libraryless. Click here for Pure Java version (1041L/7K).
1 | !7 |
2 | |
3 | sclass BetterThreadLocal<A> {
|
4 | Map<Thread, A> map = newWeakHashMap(); |
5 | |
6 | A get() {
|
7 | ret map.get(currentThread()); |
8 | } |
9 | |
10 | void set(A a) {
|
11 | mapPutOrRemove(map, currentThread(), a); |
12 | } |
13 | } |
14 | |
15 | static new BetterThreadLocal<S> tl; |
16 | |
17 | p {
|
18 | assertNull(tl!); |
19 | tl.set("hello");
|
20 | assertEq("hello", tl!);
|
21 | startAndJoinThread(r {
|
22 | assertNull(tl!); |
23 | }); |
24 | tl.set(null); |
25 | assertNull(tl!); |
26 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1011380 |
| Snippet name: | ThreadLocal Alternative [OK] |
| Eternal ID of this version: | #1011380/4 |
| Text MD5: | 4e8512cbe685ea1f4421be63129fa90e |
| Transpilation MD5: | c8cf3f959d030e2277b6e674497f3ba3 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-10-26 08:14:48 |
| Source code size: | 419 bytes / 26 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 945 / 2078 |
| Version history: | 3 change(s) |
| Referenced in: | [show references] |