黑马程序员技术交流社区
标题:
关于线程安全类的问题
[打印本页]
作者:
冯佩
时间:
2013-1-25 20:22
标题:
关于线程安全类的问题
本帖最后由 张向辉 于 2013-1-26 16:43 编辑
看教程我们知道StringBuffer是线程同步的,而StringBuilder是线程不同步的,除了看API,我们还有什么方法能知道某个类是否是线程同步的呢?还有,同步是因为有锁,但API中的同步类都没有加锁,是不是锁被封装到了内部呢?
作者:
黑马张英涛
时间:
2013-1-25 20:28
看源代码- -!以下摘自源代码:
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
int dstBegin)
{
super.getChars(srcBegin, srcEnd, dst, dstBegin);
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
public synchronized void setCharAt(int index, char ch) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
value[index] = ch;
}
public synchronized StringBuffer append(Object obj) {
super.append(String.valueOf(obj));
return this;
}
public synchronized StringBuffer append(String str) {
super.append(str);
return this;
}
复制代码
作者:
黄锦成
时间:
2013-1-25 20:34
这个要看API对于类的介绍。这个要靠自己的积累了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2