Harmony
  1. Harmony
  2. HARMONY-6690

java.lang.InheritableThreadLocal didn't set java.lang.Thread

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.0M15
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None
    • Environment:
      all
    • Estimated Complexity:
      Unknown

      Description

      /harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadLocal.java
      uses localValues field of thread. InheritableThreadLocal should use inheritableValues in initValues() and
      values() method.

      =============
      Thread:
      157 /*
      158 * ThreadLocal values: local and inheritable
      159 *
      160 */
      161 ThreadLocal.Values localValues;
      162 ThreadLocal.Values inheritableValues;
      ================
      ThreadLocal:
      100 /**
      101 * Creates Values instance for this thread and variable type.
      102 */
      103 Values initializeValues(Thread current)

      { 104 return current.localValues = new Values(); 105 }

      106
      107 /**
      108 * Gets Values instance for this thread and variable type.
      109 */
      110 Values values(Thread current)

      { 111 return current.localValues; 112 }

        Activity

        Hide
        dafeng added a comment -

        The case to test inherited threadlocal
        ===================
        package second;

        public class TestThreadLocal {
        public static void main(String[] args) {
        TestThreadLocal ttl=new TestThreadLocal();
        final InheritableThreadLocal t=new InheritableThreadLocal();
        A a1=ttl.new A(t,"a1");
        A a2=ttl.new A(t,"a2");
        a1.start();
        a2.start();
        try

        { Thread.currentThread().sleep(1000); }

        catch(Exception e)

        { e.printStackTrace(); }

        synchronized(a1)

        { a1.notify(); }

        synchronized(a2)

        { a2.notify(); }

        System.out.println(t.get());
        }
        class A extends Thread{
        ThreadLocal t;
        String value;
        public A(ThreadLocal t,String value)

        { this.t=t; this.value=value; }

        @Override
        public void run() {
        t.set(value);
        try{
        synchronized(this)

        { this.wait(); }

        }catch(Exception e)

        { e.printStackTrace(); }

        System.out.println(t.get());
        Thread z=new Thread(){

        @Override
        public void run()

        { System.out.println("inh"); System.out.println(t.get()); }

        };
        z.start();
        }
        }
        }

        Show
        dafeng added a comment - The case to test inherited threadlocal =================== package second; public class TestThreadLocal { public static void main(String[] args) { TestThreadLocal ttl=new TestThreadLocal(); final InheritableThreadLocal t=new InheritableThreadLocal(); A a1=ttl.new A(t,"a1"); A a2=ttl.new A(t,"a2"); a1.start(); a2.start(); try { Thread.currentThread().sleep(1000); } catch(Exception e) { e.printStackTrace(); } synchronized(a1) { a1.notify(); } synchronized(a2) { a2.notify(); } System.out.println(t.get()); } class A extends Thread{ ThreadLocal t; String value; public A(ThreadLocal t,String value) { this.t=t; this.value=value; } @Override public void run() { t.set(value); try{ synchronized(this) { this.wait(); } }catch(Exception e) { e.printStackTrace(); } System.out.println(t.get()); Thread z=new Thread(){ @Override public void run() { System.out.println("inh"); System.out.println(t.get()); } }; z.start(); } } }

          People

          • Assignee:
            Unassigned
            Reporter:
            dafeng
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development