`
- 浏览:
364519 次
- 性别:
- 来自:
Alien
-
java数据结构:ConcurrentSkipListSet<E>与CopyOnWriteArraySet<E>
分类: java_数据结构 java_线程2012-07-05 13:59 313人阅读 收藏 举报
- import java.util.concurrent.ConcurrentSkipListSet;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
-
- import org.junit.Test;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class ConcurrentSkipListSetTest {
-
- private static ConcurrentSkipListSet<Student> listSet = new ConcurrentSkipListSet<Student>();
-
- static {
- for(int i = 1; i <= 30; i++){
- listSet.add(new Student(new Long(i)));
- }
- }
-
- public static void main(String[] args) {
-
- ExecutorService threadPool = Executors.newFixedThreadPool(3);
- threadPool.execute(new Runnable() {
- public void run() {
- while(listSet.size() != 0){
- sop(Thread.currentThread().getName()+ " : " + listSet.pollFirst());
- }
- }
- });
-
- threadPool.execute(new Runnable() {
- public void run() {
- while(listSet.size() != 0){
- sop(Thread.currentThread().getName()+ " : " + listSet.pollLast());
- }
- }
- });
-
- threadPool.execute(new Runnable() {
- public void run() {
- while(listSet.size() != 0){
- sop(Thread.currentThread().getName()+ " : " + listSet.pollFirst());
- }
- }
- });
- }
-
- @Test
- public void test(){
- }
-
- private static void sop(Object obj){
- System.out.println(obj);
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
ConcurrentSkipListSet 是Java中的一个线程安全的有序集合类,它基于跳表(Skip List)数据结构实现。 下面是关于 ConcurrentSkipListSet 的一些重要信息: 线程安全性:ConcurrentSkipListSet 是线程安全的,可以...
主要为大家详细介绍了Java concurrency集合之ConcurrentSkipListSet的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
线程安全set:ConcurrentSkipListSet、CopyOnWriteArraySet、ConcurrentHashMap.newKeySet()、Collections.synchronizedSet(set) 分布式技术 缓存穿透: 请求去查询缓存数据库中根本就不存在的数据。解决方案: 缓存...
2.HashSet,TreeSet -- CopyONWriteArraySet,ConcurrentSkipListSet 3.hashMap , treeMap -- ConcurrentHashMap,ConcurentSkipListMap(key有序,支持更高并发) ## Concurrent同步工具类 countDownLatch ...
Java并发编程 背景介绍 并发历史 必要性 进程 资源分配的最小单位 线程 CPU调度的最小单位 线程的优势 (1)如果设计正确,多线程程序可以通过提高处理器资源的利用率来提升系统吞吐率 ...
以循环1000000万次为标准! 定义如下数组 public static char[] chars = {'A','B','C'...ConcurrentSkipListSet , CopyOnWriteArraySet , EnumSet…, HashSet JobStateReasons , LinkedHashSet , TreeSet Map接口 …….
第一章 线程基础、线程之间...1. ConcurrentSkipListMap和ConcurrentSkipListSet: 60 2. 写时复制容器 60 五、阻塞队列 60 第五章 JMH性能测试 62 1、 JMH环境搭建 62 2、 执行 63 3、 基本概念 63 4、 注解与选项 63