线程安全性问题
来源:互联网 发布:计算机算法书籍推荐 编辑:程序博客网 时间:2024/05/29 12:02
package com.nsn.sync;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class SyncThread {private int value;public int getValue() {return value++;}public static void main(String[] args) {final SyncThread us = new SyncThread();List list = new ArrayList<>();Set set = new HashSet<>();for (int i = 0; i < 1000; i++) {Thread thread = new Thread("thread" + i) {@Overridepublic void run() {for (int i = 0; i < 100; i++) {int value = us.getValue();set.add(value);System.out.println(value + " " + super.getName());}}};list.add(thread);}for (Thread thread : list) {thread.start();}try {Thread.sleep(10000L);} catch (InterruptedException e) {e.printStackTrace();}System.out.println(set.size());}}
0 0
- Servlet线程安全性问题
- Servlet线程安全性问题
- Servlet线程安全性问题
- Servlet线程安全性问题
- Servlet线程安全性问题
- Servlet线程安全性问题
- 线程安全性问题
- Servlet线程安全性问题
- servlet线程安全性问题
- Servlet线程安全性问题
- Servlet线程安全性问题
- 线程安全性问题
- 线程安全性问题
- Servlet线程安全性问题
- 线程安全性问题
- Servle t线程安全性问题
- IConfigurationSectionHandler的线程安全性问题
- servlet线程安全性问题理解
- iOS沙盒文件存储
- Spring+SpringMVC+Redis
- RadioButton和HorizontalScrollView实现分类标签
- (POJ2777)Count Color <经典:线段树区间修改 + 或运算记颜色数>
- boost_处理时间
- 线程安全性问题
- 下行资源分配类型
- linux内核list.h
- PAT 1096 Consecutive Factors (暴力,最大连续乘积)
- chown命令--Linux命令应用大词典729个命令解读
- 利用JDBC连接Oracle数据库
- Ubuntu下进行真机调试
- 十五周—判断 字符回文
- eclipse svn问题