同步栈(安全栈):

org.apache.tomcat.util.collections.SynchronizedStack
通过stack栈锁来控制栈中获取的类T。通过push、pop和clear方法操作栈对象。栈初始化大小是128,没有上限。 初始化:
public SynchronizedStack() {
this(DEFAULT_SIZE:128, DEFAULT_LIMIT:-1);
} 压入栈:
public synchronized boolean push(T obj) {
index++;
if (index == size) {
if (limit == -1 || size < limit) {
expand();
} else {
index--;
return false;
}
}
stack[index] = obj;
return true;
}
private void expand() {
int newSize = size * 2;
if (limit != -1 && newSize > limit) {
newSize = limit;
}
Object[] newStack = new Object[newSize];
System.arraycopy(stack, 0, newStack, 0, size);
// This is the only point where garbage is created by throwing away the
// old array. Note it is only the array, not the contents, that becomes
// garbage.
stack = newStack;
size = newSize;
} 获取栈对象:
public synchronized T pop() {
if (index == -1) {
return null;
}
T result = (T) stack[index];
stack[index--] = null;
return result;
} 清除栈释放资源:
public synchronized void clear() {
if (index > -1) {
for (int i = 0; i < index + 1; i++) {
stack[i] = null;
}
}
index = -1;
}
举例:  

最新文章

  1. 使用Ring Buffer构建高性能的文件写入程序
  2. php广告图片循环播放 幻灯片效果
  3. SPRING 标签库
  4. git/ssh捋不清的几个问题
  5. eclipse设置及快捷键
  6. Unsupported configuration attributes: [FILE_UPLOAD]
  7. 无法启动此程序,因为计算机中丢失MSVCP110.dll
  8. NYOJ-228 士兵杀敌5
  9. css选择器nth-child()和nth-of-type()的应用
  10. win8 任务栏不合并隐藏标题
  11. iOS真机调试之我见
  12. CSS复习第一天(简单规范)
  13. php导出excel数据
  14. UVA 11388-GCD LCM(数学)
  15. 办理卡尔加里大学(本科)学历认证『微信171922772』calgary学位证成绩单使馆认证University of calgary
  16. mysql 入门 基本命令
  17. unity实现剧情对话
  18. GitLab push除发Jenkins事件
  19. OLAP + MDX
  20. 1.html基础标签:文本+链接+图片

热门文章

  1. winform上传文件到服务器——资料整理
  2. Centos7.3云服务器上安装Nginx、MySQL、JDK、Tomcat环境
  3. pandas速查手册(中文版)
  4. idea的基础设置
  5. 圆柱模板行业B2B站点打造MIP推送+熊掌号推送+历史普通推送插件
  6. BZOJ3277 串 和 BZOJ3473 字符串
  7. arp和rarp协议
  8. 180908 input
  9. learning java AWT 布局管理器CardLayout
  10. 2017.10.3 国庆清北 D3T2 公交车