public String toString(){
StringBuffer buffer = new StringBuffer();
buffer.append('<');
buffer.append(this.name);
buffer.append('>');
return buffer.toString();
}这段代码线程安全吗??
StringBuffer buffer = new StringBuffer();
buffer.append('<');
buffer.append(this.name);
buffer.append('>');
return buffer.toString();
}这段代码线程安全吗??
解决方案 »
- -------------------大家在开发系统的时候,都是开发到什么阶段开始在数据库建立VIEW---------------------
- 急! 用mysql 遇到的问题!
- Java中添加Canvas 的问题!
- 正则表达式 \d* 的一个小问题
- 怎样设置JTextPane
- 坦克大战项目课堂实录视频教程_j2se_eclipse_debug_详尽_透彻_手把手
- JAVA初学者的苦恼,运行java Person_Sort 怎么总是出错啊!请高手指点迷津啊!将不胜感激 呵呵
- 大家帮帮忙看看这个FTP程序中的列表操作为什么总是不正确?
- 在PDF中加入图片,用Java实现
- 请问有关JFrame的问题
- 为什么binarySearch返回结果是不确定的??
- 有个问题一直不明白。
stringBuffer本身的内部实现是现场安全的!
这是源码的片段代码:
public synchronized int length() {
return count;
} public synchronized int capacity() {
return value.length;
}
public synchronized void ensureCapacity(int minimumCapacity) {
if (minimumCapacity > value.length) {
expandCapacity(minimumCapacity);
}
} /**
* @since 1.5
*/
public synchronized void trimToSize() {
super.trimToSize();
}
StringBuffer里头有很多synchronized 方法LZ建议以后这种问题,看看源码,对学习有好处
super.append(String.valueOf(obj));
return this;
}
但是多个append线程就不安全了。
请参考:
http://hi.baidu.com/gabe2008/blog/item/c1d7e62a28da21f4e7cd40d8.html