List
| package com.luoKing.unsafe; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.UUID; |
| import java.util.Vector; |
| import java.util.concurrent.CopyOnWriteArrayList; |
| import java.util.concurrent.TimeUnit; |
| |
| public class listTest { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public static void main(String[] args) { |
| List<String> list = new Vector<>(); |
| for (int i = 1; i <= 10; i++) { |
| |
| |
| |
| |
| |
| new Thread(()->{ |
| |
| list.add(UUID.randomUUID().toString().substring(0,5)); |
| System.out.println(list); |
| },String.valueOf(i)).start(); |
| } |
| } |
| } |
| |
Set
| package com.luoKing.unsafe; |
| |
| import java.util.*; |
| import java.util.concurrent.CopyOnWriteArraySet; |
| |
| |
| |
| |
| |
| |
| |
| |
| public class SetTest { |
| public static void main(String[] args) { |
| |
| Set<Object> set = Collections.synchronizedSet(new HashSet<>()); |
| for (int i = 0; i < 20; i++) { |
| new Thread(()->{ |
| set.add(UUID.randomUUID().toString().substring(0,5)); |
| System.out.println(set); |
| }).start(); |
| } |
| } |
| |
| } |
| |
Map
| package com.luoKing.unsafe; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| import java.util.UUID; |
| import java.util.concurrent.ConcurrentHashMap; |
| |
| |
| |
| |
| |
| |
| |
| public class MapTest { |
| |
| public static void main(String[] args) { |
| Map<String, String> map = new ConcurrentHashMap<>(); |
| |
| for (int i = 0; i < 200; i++) { |
| new Thread(()->{ |
| map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0,5)); |
| System.out.println(map); |
| },String.valueOf(i)).start(); |
| } |
| } |
| } |
| |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决