Thread

public class Thread001 {
	/**
	 *  正常
	 * "Finalizer" daemon prio=10 tid=0x00007fa384089000 nid=0x7c7d in Object.wait() [0x00007fa37e1fb000]
   		java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000007acf61310> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:133)
        - locked <0x00000007acf61310> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:149)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)

		"Reference Handler" daemon prio=10 tid=0x00007fa384087000 nid=0x7c7c in Object.wait() [0x00007fa37e2fc000]
   		java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000007acf611e8> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
        - locked <0x00000007acf611e8> (a java.lang.ref.Reference$Lock)
	 */
	
	public static void main(String[] args) {
		Tt t = new Tt("test");
		//t.start();
		System.out.println(t);
		try {
			System.out.println("------------------begin sleep 50 s");
			Thread.sleep(50000);
			System.out.println("------------------end sleep");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public static class Tt extends Thread {
		
		//public  static Object obj = new Object();
		
		private static AtomicInteger s_count = new AtomicInteger(0); 
		
		public Tt (String s) {
			super(s);
		}
		@Override
		public void run() {
			try {
				/**
				 *  this.sleep(50000);
				 * 	"test" prio=10 tid=0x00007f27d80d7000 nid=0x7b04 waiting on condition [0x00007f27d4d6a000]
   					java.lang.Thread.State: TIMED_WAITING (sleeping)
        			at java.lang.Thread.sleep(Native Method)
        			at com.owen.thread.Thread001$Tt.run(Thread001.java:41)
				 */
				//this.sleep(50000);
				System.out.println("this.wait()..............");
				synchronized (this) {
					/**
					 *  this.wait();
					 *  "test" prio=10 tid=0x00007fa3840d7000 nid=0x7c83 in Object.wait() [0x00007fa37dbf5000]
   						java.lang.Thread.State: WAITING (on object monitor)
        				at java.lang.Object.wait(Native Method)
        				- waiting on <0x00000007acfab070> (a com.owen.thread.Thread001$Tt)
        				at java.lang.Object.wait(Object.java:502)
        				at com.owen.thread.Thread001$Tt.run(Thread001.java:58)
        				- locked <0x00000007acfab070> (a com.owen.thread.Thread001$Tt)
					 */
					this.wait();
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}

 

你可能感兴趣的:(thread)