[ https://issues.apache.org/jira/browse/HARMONY-6690?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13139605#comment-13139605
]
dafeng commented on HARMONY-6690:
---------------------------------
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();
}
}
}
> java.lang.InheritableThreadLocal didn't set java.lang.Thread
> -------------------------------------------------------------
>
> Key: HARMONY-6690
> URL: https://issues.apache.org/jira/browse/HARMONY-6690
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Affects Versions: 5.0M15
> Environment: all
> Reporter: dafeng
> Priority: Minor
>
> /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 }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
|