From 07149729cc4c629200a0ca8f8e63f54ee05601c8 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 5 Feb 2020 14:39:23 +0100 Subject: [PATCH] Use correct system property name in PooledByteBufAllocator (io.netty.allocator.cacheTrimIntervalMillis) (#9994) Motivation: We had a typo in the system property name that was used to lookup the cache trime interval. We should ensure we use the correct naming when lookup the property Modifications: - Support the old and the new (correct) naming of the property when configure the cache trim interval. - Log something if someone uses the old (deprecated) name Result: Fixes https://github.com/netty/netty/issues/9981 --- .../netty/buffer/PooledByteBufAllocator.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java b/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java index 610d7aeb5e..3d4bc946a2 100644 --- a/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java +++ b/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java @@ -124,8 +124,22 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator implements DEFAULT_CACHE_TRIM_INTERVAL = SystemPropertyUtil.getInt( "io.netty.allocator.cacheTrimInterval", 8192); - DEFAULT_CACHE_TRIM_INTERVAL_MILLIS = SystemPropertyUtil.getLong( - "io.netty.allocation.cacheTrimIntervalMillis", 0); + if (SystemPropertyUtil.contains("io.netty.allocation.cacheTrimIntervalMillis")) { + logger.warn("-Dio.netty.allocation.cacheTrimIntervalMillis is deprecated," + + " use -Dio.netty.allocator.cacheTrimIntervalMillis"); + + if (SystemPropertyUtil.contains("io.netty.allocator.cacheTrimIntervalMillis")) { + // Both system properties are specified. Use the non-deprecated one. + DEFAULT_CACHE_TRIM_INTERVAL_MILLIS = SystemPropertyUtil.getLong( + "io.netty.allocator.cacheTrimIntervalMillis", 0); + } else { + DEFAULT_CACHE_TRIM_INTERVAL_MILLIS = SystemPropertyUtil.getLong( + "io.netty.allocation.cacheTrimIntervalMillis", 0); + } + } else { + DEFAULT_CACHE_TRIM_INTERVAL_MILLIS = SystemPropertyUtil.getLong( + "io.netty.allocator.cacheTrimIntervalMillis", 0); + } DEFAULT_USE_CACHE_FOR_ALL_THREADS = SystemPropertyUtil.getBoolean( "io.netty.allocator.useCacheForAllThreads", true);