摘要: StringBuilder--------------------------------------------------------------在JDK1.5版本之后出现了StringBuilder与StringBuffer是线程同步,StringBuilder是线程不同步。单线程建议使用StringBuilder,多线程建议使用StringBuffer.==============================================================升级的三个因素:1,提高效率2,简化书写3,提高安全性开发中建议使用StringBuilder,若遇到多线程时. 阅读全文
posted @ 2013-01-15 22:55 陈晓明 阅读(194) 评论(0) 推荐(0) 编辑
摘要: StringBuffer-----------------------------------------------------------------------------------StringBuffer 是字符串缓冲区,是一个容器特点:1,长度是可以变化的2,可以直接操作多个数据类型3,最终会通过toString()变成字符串CURDCreate Update Read Delete==================================================================================1,存储 StringBuffer . 阅读全文
posted @ 2013-01-15 22:48 陈晓明 阅读(359) 评论(0) 推荐(0) 编辑
摘要: String-----------------------------------------------------------------------------------------一、String类适用于描述字符串事物。 那么它就提供了多个方法对字符串进行操作。常见的操作有哪些?"abcd"1,获取 1.1 字符串中的包含的字符数,也就是字符串的长度。 int length() : 获取长度。 1.2 根据位置获取位置上某个字符。 char charAt(int index): 1.3 根据字符获取该字符在字符串中位置 int indexOf(int ch) :返 阅读全文
posted @ 2013-01-15 22:34 陈晓明 阅读(273) 评论(0) 推荐(0) 编辑
摘要: 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" 阅读全文
posted @ 2013-01-15 14:10 陈晓明 阅读(455) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-01-15 14:10 陈晓明 阅读(459) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-01-15 13:16 陈晓明 阅读(566) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-01-15 13:10 陈晓明 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-01-15 12:15 陈晓明 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 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.. 阅读全文
posted @ 2013-01-15 12:07 陈晓明 阅读(321) 评论(0) 推荐(0) 编辑
摘要: classThreadCommunicationDemo{publicstaticvoidmain(String[]args){Resourceresource=newResource();Inputinput=newInput(resource);Outputoutput=newOutput(resource);newThread(input,"inputthread").start();newThread(output,"outputthread").start();}}classInputimplementsRunnable{privateReso 阅读全文
posted @ 2013-01-15 11:23 陈晓明 阅读(216) 评论(0) 推荐(0) 编辑
摘要: classThreadCommunicationDemo{publicstaticvoidmain(String[]args){Resourceresource=newResource();Inputinput=newInput(resource);Outputoutput=newOutput(resource);newThread(input,"inputthread").start();newThread(output,"outputthread").start();}}classInputimplementsRunnable{privateReso 阅读全文
posted @ 2013-01-15 11:15 陈晓明 阅读(248) 评论(0) 推荐(0) 编辑