Guava Multimap putAll OOM?

近日使用ArrayListMultimap的putAll时犯了一个错误,先看一下Code,Pos1、2、3、4输出什么值?

//test1
Set<Long> sets = new HashSet<>();
sets.add(1L);
sets.add(2L);

Multimap<String, Long> maps = ArrayListMultimap.create();

maps.putAll("A", sets); // ①
System.out.println("Pos1:" + maps.get("A").size());

maps.putAll("A", sets); // ②
System.out.println("Pos2:" + maps.get("A").size());

// test2
Multimap<String, Long> maps2 = ArrayListMultimap.create();

maps2.put("A", 1L);
maps2.put("A", 2L);
System.out.println("Pos3:" + maps2.get("A").size());

This chapter requires login to view full content. You are viewing a preview.

Login to View Full Content

Course Curriculum

3

框架与 I/O:Spring、Netty 与 Web 容器

理解 Spring Boot 自动装配、AOP 与事务原理,掌握 Netty Reactor 模型及 Tomcat 连接处理机制,构建高内聚、易扩展的应用服务层。
4

高性能中间件:消息、缓存与存储

熟练运用 MySQL 索引/事务、Redis 缓存策略、Kafka/RocketMQ 消息可靠性,以及 ZooKeeper 分布式协调,搭建稳定、解耦的分布式数据底座。
6

云原生:容器化、可观测性与工程效能

通过 Docker/K8s 实现弹性部署,集成 Metrics/Logs/Traces 构建可观测体系,推动 DevOps 与自动化,让架构在云上持续交付与进化。