Package thread;import org.omg.portableserver.thread_policy_id;import java.util.arraylist;import java.util.HashMap;import java.util.concurrent.locks.Condition;import java.util.concurrent.locks.reentrantlock;class node{ public int num; node (int nums) { num=nums; } public node next;} class mytest implements runnable{ string s=null; node n1=new node (1); node n2=new node (2); node n3=new node (3); @Override public void run () { n1.next=n2; n2.next=n3; n3.next=null; node e=n1; while (e!=null) { node n1= E.next; system.out.println ("Current thread is" + Thread.CurrentThread (). GetName ()); if ( Thread.CurrentThread (). GetName (). Equals ("Thread-0")) { try { system.out.println ("Thread-0 to block"); thread.sleep (10000); } catch (IntERRUPTEDEXCEPTION E1) { e1.printstacktrace (); } if (e==null) { system.out.println ("E is not owned separately" in the thread); } else { System.out.println ("individually owned"); &nBsp System.out.println (E.num); } } system.out.println (Thread.CurrentThread (). GetName () + + + + E.num); e=e.next; if (e==null) { system.out.println ("in" +thread.currentthread (). GetName () + "E is already empty"); } } }}public class Test1 { Public static void main (String[] args) { mytest mytEst=new mytest (); thread t1=new thread (myTest); thread t2=new thread (myTest); t1.start (); t2.start (); }}
The result of this code operation is as follows!
It turns out that each thread has a separate reference to the Run Method!
Note that if I declare node1 as a method of a class, it will not be owned by the thread alone!
Each thread is used separately for the reference variable of the object?