線程的簡單示例

class RunnableImpl implements Runnable{
	public void run(){
		for(int i=0;i<100;i++){
			if(i==50){
				try{
					Thread.sleep(1000);
				}
				catch(Exception e){
					System.out.println(e);
				}
			}
			System.out.println("RunnableImpl-->"+i);
		}
	}
}


class Test{
	public static void main(String args[]){
		RunnableImpl ri=new RunnableImpl();
		Thread t=new Thread(ri);//將ri作爲參數傳給Thread
		t.setPriority(9);//設置優先級爲9
		t.start();
		System.out.println(t.getPriority());//獲取優先級
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章