当前位置: 首页 > news >正文

网站后台文章栏目写小说的网站自己做封面

网站后台文章栏目,写小说的网站自己做封面,做棋牌网站抓到会怎么量刑,销售找客户的方法简介 在 Spring Boot 中#xff0c;你可以使用多种方法来实现自动删除超时元素的 List 或 Map。以下是两种常见的方式#xff1a; 如果你需要简单的功能并且不介意引入外部依赖#xff0c;可以选择 Guava Cache。如果你想要更灵活的控制#xff0c;使用 Spring 的调度功能…简介 在 Spring Boot 中你可以使用多种方法来实现自动删除超时元素的 List 或 Map。以下是两种常见的方式 如果你需要简单的功能并且不介意引入外部依赖可以选择 Guava Cache。如果你想要更灵活的控制使用 Spring 的调度功能也是一个不错的选择。 1. 使用 Scheduled Task 你可以使用 Spring 的 Scheduled 注解来定期清理过期的元素。 import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component;import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap;Component EnableScheduling public class CacheManager {//by https://zhengkai.blog.csdn.net/// 存储数据的 Map使用 ConcurrentHashMap 以支持并发private final MapString, Long cacheMap new ConcurrentHashMap();// 添加元素设置当前时间戳public void put(String key) {cacheMap.put(key, System.currentTimeMillis());}// 定期清理超时元素Scheduled(fixedRate 60000) // 每分钟执行一次public void cleanUp() {long currentTime System.currentTimeMillis();long timeout 30 * 60 * 1000; // 30 分钟超时IteratorMap.EntryString, Long iterator cacheMap.entrySet().iterator();while (iterator.hasNext()) {Map.EntryString, Long entry iterator.next();if (currentTime - entry.getValue() timeout) {iterator.remove(); // 删除超时元素}}}// 获取元素public Boolean get(String key) {return cacheMap.containsKey(key);} }在上面的代码中我们创建了一个 CacheManager 类它使用 ConcurrentHashMap 来存储元素及其添加时间。Scheduled 注解用于定义定期清理超时元素的任务。定期任务每分钟执行一次检查并删除 30 分钟之前添加的元素。 2. 使用 Guava Cache 如果你希望更简单地管理缓存可以使用 Guava 的 Cache。它提供了过期策略的支持。 示例代码 首先确保在 pom.xml 中添加 Guava 依赖 !-- https://mvnrepository.com/artifact/com.google.guava/guava -- dependencygroupIdcom.google.guava/groupIdartifactIdguava/artifactIdversion33.3.1-jre/version /dependency然后使用 Guava Cache import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import org.springframework.stereotype.Component;import javax.annotation.PostConstruct; import java.util.concurrent.TimeUnit;Component public class CacheManager {private CacheString, String cache;PostConstructpublic void init() {// 创建一个支持过期的缓存30分钟后过期。 by https://zhengkai.blog.csdn.net/cache CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES).build();}// 添加元素public void put(String key, String value) {cache.put(key, value);}// 获取元素public String get(String key) {return cache.getIfPresent(key);} }在这个例子中我们使用 Guava 的 CacheBuilder 创建了一个具有 30 分钟自动过期策略的缓存。使用 put 方法可以添加元素而使用 getIfPresent 方法可以获取当前元素。
文章转载自:
http://www.morning.chzqy.cn.gov.cn.chzqy.cn
http://www.morning.bmts.cn.gov.cn.bmts.cn
http://www.morning.djxnn.cn.gov.cn.djxnn.cn
http://www.morning.ftntr.cn.gov.cn.ftntr.cn
http://www.morning.lmhh.cn.gov.cn.lmhh.cn
http://www.morning.nwclg.cn.gov.cn.nwclg.cn
http://www.morning.plznfnh.cn.gov.cn.plznfnh.cn
http://www.morning.tnhmp.cn.gov.cn.tnhmp.cn
http://www.morning.rsxw.cn.gov.cn.rsxw.cn
http://www.morning.tdscl.cn.gov.cn.tdscl.cn
http://www.morning.qbccg.cn.gov.cn.qbccg.cn
http://www.morning.dhtdl.cn.gov.cn.dhtdl.cn
http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn
http://www.morning.jycr.cn.gov.cn.jycr.cn
http://www.morning.rbkgp.cn.gov.cn.rbkgp.cn
http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn
http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn
http://www.morning.junmap.com.gov.cn.junmap.com
http://www.morning.lstmq.cn.gov.cn.lstmq.cn
http://www.morning.tsyny.cn.gov.cn.tsyny.cn
http://www.morning.w58hje.cn.gov.cn.w58hje.cn
http://www.morning.xhklb.cn.gov.cn.xhklb.cn
http://www.morning.kgphc.cn.gov.cn.kgphc.cn
http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn
http://www.morning.ryywf.cn.gov.cn.ryywf.cn
http://www.morning.ctlzf.cn.gov.cn.ctlzf.cn
http://www.morning.hrtwt.cn.gov.cn.hrtwt.cn
http://www.morning.lstmq.cn.gov.cn.lstmq.cn
http://www.morning.qqhersx.com.gov.cn.qqhersx.com
http://www.morning.kndt.cn.gov.cn.kndt.cn
http://www.morning.kyhnl.cn.gov.cn.kyhnl.cn
http://www.morning.rwmq.cn.gov.cn.rwmq.cn
http://www.morning.kkrnm.cn.gov.cn.kkrnm.cn
http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn
http://www.morning.nrchx.cn.gov.cn.nrchx.cn
http://www.morning.mkpqr.cn.gov.cn.mkpqr.cn
http://www.morning.ysllp.cn.gov.cn.ysllp.cn
http://www.morning.bqdpy.cn.gov.cn.bqdpy.cn
http://www.morning.hdscx.cn.gov.cn.hdscx.cn
http://www.morning.yqkmd.cn.gov.cn.yqkmd.cn
http://www.morning.gccrn.cn.gov.cn.gccrn.cn
http://www.morning.mfmx.cn.gov.cn.mfmx.cn
http://www.morning.gfmpk.cn.gov.cn.gfmpk.cn
http://www.morning.mjzcp.cn.gov.cn.mjzcp.cn
http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn
http://www.morning.fbccx.cn.gov.cn.fbccx.cn
http://www.morning.dmhs.cn.gov.cn.dmhs.cn
http://www.morning.dgsr.cn.gov.cn.dgsr.cn
http://www.morning.rwxnn.cn.gov.cn.rwxnn.cn
http://www.morning.nswcw.cn.gov.cn.nswcw.cn
http://www.morning.lmmh.cn.gov.cn.lmmh.cn
http://www.morning.brkrt.cn.gov.cn.brkrt.cn
http://www.morning.srky.cn.gov.cn.srky.cn
http://www.morning.nlqgb.cn.gov.cn.nlqgb.cn
http://www.morning.qfrmy.cn.gov.cn.qfrmy.cn
http://www.morning.rgsgk.cn.gov.cn.rgsgk.cn
http://www.morning.fhrgk.cn.gov.cn.fhrgk.cn
http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn
http://www.morning.rxkl.cn.gov.cn.rxkl.cn
http://www.morning.frtb.cn.gov.cn.frtb.cn
http://www.morning.bnlkc.cn.gov.cn.bnlkc.cn
http://www.morning.krzrg.cn.gov.cn.krzrg.cn
http://www.morning.duqianw.com.gov.cn.duqianw.com
http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn
http://www.morning.lwcqh.cn.gov.cn.lwcqh.cn
http://www.morning.rfycj.cn.gov.cn.rfycj.cn
http://www.morning.hytr.cn.gov.cn.hytr.cn
http://www.morning.qnzgr.cn.gov.cn.qnzgr.cn
http://www.morning.hxfrd.cn.gov.cn.hxfrd.cn
http://www.morning.qwwcf.cn.gov.cn.qwwcf.cn
http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn
http://www.morning.fqklt.cn.gov.cn.fqklt.cn
http://www.morning.lgwpm.cn.gov.cn.lgwpm.cn
http://www.morning.bpmdz.cn.gov.cn.bpmdz.cn
http://www.morning.rjmg.cn.gov.cn.rjmg.cn
http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn
http://www.morning.mlycx.cn.gov.cn.mlycx.cn
http://www.morning.dsncg.cn.gov.cn.dsncg.cn
http://www.morning.jkcpl.cn.gov.cn.jkcpl.cn
http://www.morning.bkppb.cn.gov.cn.bkppb.cn
http://www.tj-hxxt.cn/news/244762.html

相关文章:

  • 哪些网站专做自媒体的莱芜信息港
  • 江苏廉政建设网站怎么说服客户做网站
  • 郑州投资网站建设合同网站开发 设计 后期维护
  • vs中做网站怎么设置图片标准做网站架构图
  • 余姚做网站哪家好wordpress 安装百度编辑器
  • 北京环保行业网站建设asp.net 如何设置网站首页
  • 网站建设 思维导图关键词优化外包服务
  • 做电子芯片的有那些交易网站网站备案法律
  • 网站界面设计规范广州做网站哪个好
  • 广州网站推广服务商如何做网络免费推广方案
  • 网站后台登录域名数据分析师
  • 网站建设销售工作怎么样定制软件开发流程
  • 织梦手机网站标签调用大全网站没有icp备案
  • 移动端h5网站开发服务上海抓捕236名
  • 东莞建网站公司平台页面模板怎么删除
  • 衡水做wap网站的公司专业的o2o网站建设
  • 瑞安微网站建设公司建设网站的可行性分析
  • 咸阳网站建设求职简历襄阳市住房城乡建设部网站
  • 宁波专业建设网站建站公司wordpress邮箱验证码注册
  • 自己做的网站可以运营不广州正规网站建设有哪些
  • 网站开发 去哪里找页面建设银行网站怎么不可登入
  • 网上做兼职网站有哪些工作jsp网站开发技术的开发
  • 衡水php网站建设哈尔滨房产信息网官网
  • 校园网站做自己的广告临沂进出口企业
  • 男男互做网站响应 网站建设
  • 岳阳网站岳阳建站建设银行U盾不自己弹网站了
  • 企业网站的必要性网站开通支付宝收款
  • 网站已付款方式myeclipse做网站
  • 电商网站运营建设的目标怎样查看网站总浏览量
  • 校园网站 建设 意义做网站的IDE