|
@@ -0,0 +1,48 @@
|
|
|
|
+package com.jiayue.pfr;
|
|
|
|
+
|
|
|
|
+import cn.hutool.cache.Cache;
|
|
|
|
+import cn.hutool.cache.CacheUtil;
|
|
|
|
+import cn.hutool.cache.impl.CacheObj;
|
|
|
|
+
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author xsl
|
|
|
|
+ * @since 2023/12/27
|
|
|
|
+ */
|
|
|
|
+public class TestThread {
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ Cache<String, String> fmMap = CacheUtil.newFIFOCache(50);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Thread thread1 = new Thread(() -> {
|
|
|
|
+ for (int i = 0; i < 100; i++) {
|
|
|
|
+ fmMap.put(String.valueOf(i), String.valueOf(i));
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(200);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Thread thread2 = new Thread(() -> {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(3000);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ Iterator<CacheObj<String, String>> iterator1 = fmMap.cacheObjIterator();
|
|
|
|
+ while (iterator1.hasNext()) {
|
|
|
|
+ CacheObj<String, String> entry = iterator1.next();
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
+ Object value = entry.getValue();
|
|
|
|
+ System.out.println("Key: " + key + ", Value: " + value);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ thread1.start();
|
|
|
|
+ thread2.start();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|