< prev index next >

test/micro/org/openjdk/bench/java/lang/ScopedValuesData.java

Print this page

42     static final ScopedValue<Integer> unbound = ScopedValue.newInstance();
43 
44     static final ScopedValue<AtomicReference<Integer>> sl_atomicRef = ScopedValue.newInstance();
45 
46     static final ThreadLocal<Integer> tl2 = new ThreadLocal<>();
47     static final ThreadLocal<Integer> tl3 = new ThreadLocal<>();
48     static final ThreadLocal<Integer> tl4 = new ThreadLocal<>();
49     static final ThreadLocal<Integer> tl5 = new ThreadLocal<>();
50     static final ThreadLocal<Integer> tl6 = new ThreadLocal<>();
51     static final ThreadLocal<AtomicInteger> tl_atomicInt = new ThreadLocal<>();
52 
53     static final ScopedValue.Carrier VALUES = ScopedValue
54             .where(sl1, 42).where(sl2, 2).where(sl3, 3)
55             .where(sl4, 4).where(sl5, 5).where(sl6, 6);
56 
57     public static void run(Runnable action) {
58         try {
59             tl1.set(42); tl2.set(2); tl3.set(3); tl4.set(4); tl5.set(5); tl6.set(6);
60             tl1.get();  // Create the ScopedValue cache as a side effect
61             tl_atomicInt.set(new AtomicInteger());
62             VALUES.where(sl_atomicInt, new AtomicInteger())
63                   .where(sl_atomicRef, new AtomicReference<>())
64                   .run(action);


65         } finally {
66             tl1.remove(); tl2.remove(); tl3.remove(); tl4.remove(); tl5.remove(); tl6.remove();
67             tl_atomicInt.remove();
68         }
69     }
70 }
71 

42     static final ScopedValue<Integer> unbound = ScopedValue.newInstance();
43 
44     static final ScopedValue<AtomicReference<Integer>> sl_atomicRef = ScopedValue.newInstance();
45 
46     static final ThreadLocal<Integer> tl2 = new ThreadLocal<>();
47     static final ThreadLocal<Integer> tl3 = new ThreadLocal<>();
48     static final ThreadLocal<Integer> tl4 = new ThreadLocal<>();
49     static final ThreadLocal<Integer> tl5 = new ThreadLocal<>();
50     static final ThreadLocal<Integer> tl6 = new ThreadLocal<>();
51     static final ThreadLocal<AtomicInteger> tl_atomicInt = new ThreadLocal<>();
52 
53     static final ScopedValue.Carrier VALUES = ScopedValue
54             .where(sl1, 42).where(sl2, 2).where(sl3, 3)
55             .where(sl4, 4).where(sl5, 5).where(sl6, 6);
56 
57     public static void run(Runnable action) {
58         try {
59             tl1.set(42); tl2.set(2); tl3.set(3); tl4.set(4); tl5.set(5); tl6.set(6);
60             tl1.get();  // Create the ScopedValue cache as a side effect
61             tl_atomicInt.set(new AtomicInteger());
62 
63             var carrier = VALUES.where(sl_atomicInt, new AtomicInteger())
64                   .where(sl_atomicRef, new AtomicReference<>());
65             ScopedValue.runWhere(carrier, action);
66 
67         } finally {
68             tl1.remove(); tl2.remove(); tl3.remove(); tl4.remove(); tl5.remove(); tl6.remove();
69             tl_atomicInt.remove();
70         }
71     }
72 }
73 
< prev index next >