mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
1b3a19f07e
commit
06e8e05051
@ -24,7 +24,7 @@ public class CacheUtil {
|
|||||||
* @return {@link FIFOCache}
|
* @return {@link FIFOCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> FIFOCache<K, V> newFIFOCache(int capacity, long timeout){
|
public static <K, V> FIFOCache<K, V> newFIFOCache(int capacity, long timeout){
|
||||||
return new FIFOCache<K, V>(capacity, timeout);
|
return new FIFOCache<>(capacity, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +36,7 @@ public class CacheUtil {
|
|||||||
* @return {@link FIFOCache}
|
* @return {@link FIFOCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> FIFOCache<K, V> newFIFOCache(int capacity){
|
public static <K, V> FIFOCache<K, V> newFIFOCache(int capacity){
|
||||||
return new FIFOCache<K, V>(capacity);
|
return new FIFOCache<>(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +49,7 @@ public class CacheUtil {
|
|||||||
* @return {@link LFUCache}
|
* @return {@link LFUCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> LFUCache<K, V> newLFUCache(int capacity, long timeout){
|
public static <K, V> LFUCache<K, V> newLFUCache(int capacity, long timeout){
|
||||||
return new LFUCache<K, V>(capacity, timeout);
|
return new LFUCache<>(capacity, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +61,7 @@ public class CacheUtil {
|
|||||||
* @return {@link LFUCache}
|
* @return {@link LFUCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> LFUCache<K, V> newLFUCache(int capacity){
|
public static <K, V> LFUCache<K, V> newLFUCache(int capacity){
|
||||||
return new LFUCache<K, V>(capacity);
|
return new LFUCache<>(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class CacheUtil {
|
|||||||
* @return {@link LRUCache}
|
* @return {@link LRUCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> LRUCache<K, V> newLRUCache(int capacity, long timeout){
|
public static <K, V> LRUCache<K, V> newLRUCache(int capacity, long timeout){
|
||||||
return new LRUCache<K, V>(capacity, timeout);
|
return new LRUCache<>(capacity, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +87,7 @@ public class CacheUtil {
|
|||||||
* @return {@link LRUCache}
|
* @return {@link LRUCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> LRUCache<K, V> newLRUCache(int capacity){
|
public static <K, V> LRUCache<K, V> newLRUCache(int capacity){
|
||||||
return new LRUCache<K, V>(capacity);
|
return new LRUCache<>(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +99,7 @@ public class CacheUtil {
|
|||||||
* @return {@link TimedCache}
|
* @return {@link TimedCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> TimedCache<K, V> newTimedCache(long timeout){
|
public static <K, V> TimedCache<K, V> newTimedCache(long timeout){
|
||||||
return new TimedCache<K, V>(timeout);
|
return new TimedCache<>(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +112,7 @@ public class CacheUtil {
|
|||||||
* @since 3.0.7
|
* @since 3.0.7
|
||||||
*/
|
*/
|
||||||
public static <K, V> WeakCache<K, V> newWeakCache(long timeout){
|
public static <K, V> WeakCache<K, V> newWeakCache(long timeout){
|
||||||
return new WeakCache<K, V>(timeout);
|
return new WeakCache<>(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,7 +123,7 @@ public class CacheUtil {
|
|||||||
* @return {@link NoCache}
|
* @return {@link NoCache}
|
||||||
*/
|
*/
|
||||||
public static <K, V> NoCache<K, V> newNoCache(){
|
public static <K, V> NoCache<K, V> newNoCache(){
|
||||||
return new NoCache<K, V>();
|
return new NoCache<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
package cn.hutool.cache;
|
package cn.hutool.cache;
|
||||||
|
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局缓存清理定时器池,用于在需要过期支持的缓存对象中超时任务池
|
* 全局缓存清理定时器池,用于在需要过期支持的缓存对象中超时任务池
|
||||||
*
|
|
||||||
* @author looly
|
|
||||||
*
|
*
|
||||||
|
* @author looly
|
||||||
*/
|
*/
|
||||||
public enum GlobalPruneTimer {
|
public enum GlobalPruneTimer {
|
||||||
/** 单例对象 */
|
/**
|
||||||
|
* 单例对象
|
||||||
|
*/
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
/** 缓存任务计数 */
|
/**
|
||||||
|
* 缓存任务计数
|
||||||
|
*/
|
||||||
private AtomicInteger cacheTaskNumber = new AtomicInteger(1);
|
private AtomicInteger cacheTaskNumber = new AtomicInteger(1);
|
||||||
|
|
||||||
/** 定时器 */
|
/**
|
||||||
|
* 定时器
|
||||||
|
*/
|
||||||
private ScheduledExecutorService pruneTimer;
|
private ScheduledExecutorService pruneTimer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,8 +40,8 @@ public enum GlobalPruneTimer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动定时任务
|
* 启动定时任务
|
||||||
*
|
*
|
||||||
* @param task 任务
|
* @param task 任务
|
||||||
* @param delay 周期
|
* @param delay 周期
|
||||||
* @return {@link ScheduledFuture}对象,可手动取消此任务
|
* @return {@link ScheduledFuture}对象,可手动取消此任务
|
||||||
*/
|
*/
|
||||||
@ -52,12 +56,7 @@ public enum GlobalPruneTimer {
|
|||||||
if (null != pruneTimer) {
|
if (null != pruneTimer) {
|
||||||
shutdownNow();
|
shutdownNow();
|
||||||
}
|
}
|
||||||
this.pruneTimer = new ScheduledThreadPoolExecutor(16, new ThreadFactory() {
|
this.pruneTimer = new ScheduledThreadPoolExecutor(16, r -> ThreadUtil.newThread(r, StrUtil.format("Pure-Timer-{}", cacheTaskNumber.getAndIncrement())));
|
||||||
@Override
|
|
||||||
public Thread newThread(Runnable r) {
|
|
||||||
return ThreadUtil.newThread(r, StrUtil.format("Pure-Timer-{}", cacheTaskNumber.getAndIncrement()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +70,7 @@ public enum GlobalPruneTimer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 销毁全局定时器
|
* 销毁全局定时器
|
||||||
*
|
*
|
||||||
* @return 销毁时未被执行的任务列表
|
* @return 销毁时未被执行的任务列表
|
||||||
*/
|
*/
|
||||||
public List<Runnable> shutdownNow() {
|
public List<Runnable> shutdownNow() {
|
||||||
|
@ -71,7 +71,7 @@ public abstract class AbstractCache<K, V> implements Cache<K, V> {
|
|||||||
* @since 4.5.16
|
* @since 4.5.16
|
||||||
*/
|
*/
|
||||||
private void putWithoutLock(K key, V object, long timeout) {
|
private void putWithoutLock(K key, V object, long timeout) {
|
||||||
CacheObj<K, V> co = new CacheObj<K, V>(key, object, timeout);
|
CacheObj<K, V> co = new CacheObj<>(key, object, timeout);
|
||||||
if (timeout != 0) {
|
if (timeout != 0) {
|
||||||
existCustomTimeout = true;
|
existCustomTimeout = true;
|
||||||
}
|
}
|
||||||
@ -190,10 +190,9 @@ public abstract class AbstractCache<K, V> implements Cache<K, V> {
|
|||||||
// ---------------------------------------------------------------- get end
|
// ---------------------------------------------------------------- get end
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Iterator<V> iterator() {
|
public Iterator<V> iterator() {
|
||||||
CacheObjIterator<K, V> copiedIterator = (CacheObjIterator<K, V>) this.cacheObjIterator();
|
CacheObjIterator<K, V> copiedIterator = (CacheObjIterator<K, V>) this.cacheObjIterator();
|
||||||
return new CacheValuesIterator<V>(copiedIterator);
|
return new CacheValuesIterator<>(copiedIterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,7 +42,7 @@ public class FIFOCache<K, V> extends AbstractCache<K, V> {
|
|||||||
|
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
cacheMap = new LinkedHashMap<K, CacheObj<K, V>>(capacity + 1, 1.0f, false);
|
cacheMap = new LinkedHashMap<>(capacity + 1, 1.0f, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user