摘要:
classJoinThreadDemo{publicstaticvoidmain(String[]args){JoinThreadjoinThread=newJoinThread();Threadt1=newThread(joinThread,"t1");Threadt2=newThread(joinThread,"t2");t1.start();try{t1.join();}catch(Exceptione){System.out.println(Thread.currentThread().getName()+"Exception" 阅读全文
摘要:
classThreadDemo{publicstaticvoidmain(String[]args){newThread(){publicvoidrun(){for(inti=0;i<100;i++){System.out.println(Thread.currentThread().getName()+"...."+i);}}}.start();for(inti=0;i<100;i++){System.out.println(Thread.currentThread().getName()+"...."+i);}Runnabler=newR 阅读全文
摘要:
classDaemonThreadDemo{publicstaticvoidmain(String[]args){StopThreadstopThread=newStopThread();Threadt1=newThread(stopThread,"t1");Threadt2=newThread(stopThread,"t2");t1.setDaemon(true);t2.setDaemon(true);t1.start();t2.start();intnum=0;while(true){if(num++==60){stopThread.changeFl 阅读全文
摘要:
classStopThreadDemo{publicstaticvoidmain(String[]args){StopThreadstopThread=newStopThread();Threadt1=newThread(stopThread,"t1");Threadt2=newThread(stopThread,"t2");t1.start();t2.start();intnum=0;while(true){if(num++==60){//this.changeFlag();t1.interrupt();t2.interrupt();break;}Sy 阅读全文
摘要:
classProducerConsumerDemo{publicstaticvoidmain(String[]args){Productproduct=newProduct();newThread(newProducer(product)).start();newThread(newConsumer(product)).start();newThread(newProducer(product)).start();newThread(newConsumer(product)).start();newThread(newProducer(product)).start();newThread(n 阅读全文
摘要:
classProducerConsumerDemo{publicstaticvoidmain(String[]args){Productproduct=newProduct();newThread(newProducer(product)).start();newThread(newConsumer(product)).start();}}classProduct{privateintcount;privatebooleanflag;publicsynchronizedvoidcreate(){while(this.flag){try{this.wait();}catch(Exceptio.. 阅读全文
摘要:
classThreadCommunicationDemo{publicstaticvoidmain(String[]args){Resourceresource=newResource();Inputinput=newInput(resource);Outputoutput=newOutput(resource);newThread(input,"inputthread").start();newThread(output,"outputthread").start();}}classInputimplementsRunnable{privateReso 阅读全文
摘要:
classThreadCommunicationDemo{publicstaticvoidmain(String[]args){Resourceresource=newResource();Inputinput=newInput(resource);Outputoutput=newOutput(resource);newThread(input,"inputthread").start();newThread(output,"outputthread").start();}}classInputimplementsRunnable{privateReso 阅读全文