to banq:
这里因为带有参数,所以使用单态会有麻烦
不知这样说对不对?

to:hxz

我知道,如果要单态某个类,的确需要在生成它的涵数(比如getInstance)
上加上同步,因为不加就会失去单态的作用,就我上面举的例子(代码)来说,
跟单态没有关系,就是起个比如格式化传进来的参数字符串之类的作用,那么
我真看不出有同步这类方法的必要,而且一但那样做,该方法只能在同时间允许
一个线程访问了,不是严重影响性能吗??????????????????


请正面回答,谢谢你

你好:
我的看法是这样的
跟据这里:
class Test03 { public static void main(String[] args) { StringBuffer s= new StringBuffer("good"); StringBuffer s2=new StringBuffer("bad"); test(s,s2); System.out.println(s);//9 System.out.println(s2);//10 } static void test(StringBuffer s,StringBuffer s2) { System.out.println(s);//1 System.out.println(s2);//2 s2=s;//3 s=new StringBuffer("new");//4 System.out.println(s);//5 System.out.println(s2);//6 s.append("hah");//7 s2.append("hah");//8 }}

程序的输出是:
good
bad
new
good
goodhah
bad

这是原文看了你就明白了
http://www.javaresearch.org/article/showarticle.jsp?column=1&thread=3156

难得聊天这么好,QQ或mail ?
我是新手,我正在学习 :)

有人对vector的代码分析,vector这样的工具类也提供了同步,所以性能和安全有一个平衡,你不一定要同步!只是看具体情况
但要清楚就可以了!
:)

QQ: 25415617

email: henry.t@21mail.com

等到花都开了