线程的简单示例

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());//获取优先级
	}
}


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