180个针对Java初学者的简单实例,包含了180個適合與初學者的源碼實例

源代码在线查看: consumer.java

软件大小: 234 K
上传用户: changke8311
关键词: 180 Java 初学者
下载地址: 免注册下载 普通下载 VIP

相关代码

				class Consumer extends Thread 
				{ 
					int nTime; 
					String strConsumer; 
					int count;
					public Consumer(int nTime, String strConsumer){ 
						this.nTime = nTime; 
						this.strConsumer = strConsumer;
						count=0;
					} 
					public void run(){ 
						while(true){ 
							try{ 
								System.out.println("消费者姓名:"+strConsumer+" ."); 
								Thread.sleep(nTime); 
							} catch(Exception e) { 
								e.printStackTrace(); 
							} 
							if(count++>3) break;
						} 
					} 
					static public void main(String args[]){ 
						Consumer aConsumer = new Consumer (1000, "aConsumer"); 
						aConsumer.start(); 
						Consumer bConsumer = new Consumer (2000, "bConsumer"); 
						bConsumer.start(); 
						Consumer cConsumer = new Consumer (3000, "cConsumer "); 
						cConsumer.start(); 
					} 
				} 
							

相关资源