Java thread state

status:

Method of creating threads:

class newthread the implements the Runnable {public 
    @Override 
    public void the synchronized RUN () { 
    	the while (to true) { 
    		the try { 
				//Thread.sleep(100); 
    			the wait (); 
			} the catch (InterruptedException E) { 
				e.printStackTrace (); 
			} 
    		the System .out.println ( "thread running ..."); 
    	} 
    } 
    public static void main (String [] args) { 
    	newthread new new = n-newthread (); 
    	
    	// initialize state 
		thread thread = new thread (n) ; / / create a thread, and the thread of execution tasks 

		thread.start (); // start the thread 
		the while (to true) { 
			the synchronized (the n-) { 
				System.out.println ( "main thread executed ...."); 
				the try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				n.notifyAll();
			}
		}
	}
}

  

Guess you like

Origin www.cnblogs.com/sunliyuan/p/11086740.html