小编Soe*_*ark的帖子

JVM G1GC的混合gc没有收集太多旧区域

我的服务器在CentOS 6.7上使用1.8.0_92,GC参数是'-Xms16g -Xmx16g -XX:+ UseG1GC'.所以默认的InitiatingHeapOccupancyPercent是45,G1HeapWastePercent是5,而G1MixedGCLiveThresholdPercent是85.我的服务器的混合GC从7.2GB开始,但它越来越少,最后老一代保持大于7.2GB,所以它总是尝试做并发标记.最后所有堆都耗尽并且发生了完整的GC.完全GC后,使用的旧版本低于500MB.

老一代

我很好奇为什么我的混合GC不能收集更多,看起来像实时数据不是那么多......

我曾尝试打印g1相关信息,并发现许多消息如下,看起来我的旧版包含很多实时数据,但为什么完整的GC可以收集这么多......

G1Ergonomics (Mixed GCs) do not continue mixed GCs, reason: reclaimable percentage not over threshold, candidate old regions: 190 regions, reclaimable: 856223240 bytes (4.98 %),  threshold: 5.00 %
Run Code Online (Sandbox Code Playgroud)

以下日志是将InitiatingHeapOccupancyPercent修改为15(启动并发标记为2.4GB)以加快速度的结果.

### PHASE Post-Marking
......
### SUMMARY  capacity: 16384.00 MB  used: 2918.42 MB / 17.81 %  prev-live: 2407.92 MB / 14.70 %  next-live: 2395.00 MB / 14.62 %  remset: 56.66 MB  code-roots: 0.91 MB
### PHASE Post-Sorting
....
### SUMMARY  capacity: 1624.00 MB  used: 1624.00 MB …
Run Code Online (Sandbox Code Playgroud)

java garbage-collection weak-references g1gc

32
推荐指数
1
解决办法
1367
查看次数

为互斥请求参数设计API的更好方法是什么?

当请求参数互斥时,在@Controller方法上设计API的更好方法是什么?

假设有一个API来提供与请求参数匹配的用户列表.

代码是:

public ResponseEntity getList(@RequestParam(required = false) Integer userId,
                              @RequestParam(required = false) User.Type userType,
                              @RequestParam(required = false) Integer age) {
        List<User> userList = null;
        if (userId != null) {
            //logic
            userList = getUserByUserId()
        } else if (userType != null) {
            //logic
            userList = getUserByType()
        } else if (age != null) {
            //logic
            userList = getListByAge()
        } else {
            userList = getAllWithoutCondition();
        }
        return ResponseEntity.ok(userList);
}
Run Code Online (Sandbox Code Playgroud)

这是重点:

用户无法使用多个请求参数进行查询.只有一个请求参数或没有请求参数是有效的(仅一个userId,agetype在一个请求必须存在).

我不确定为这种情况设计API的更好方法是什么.你能给我一些建议吗?

java spring api-design spring-mvc

7
推荐指数
1
解决办法
399
查看次数