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

网站建设运转wordpress酒店

网站建设运转,wordpress酒店,郑州比较好的设计公司,怎样自己做免费网站1. 功能#xff1a; map 线程安全#xff0c;能够对存入的数据设置过期#xff0c;或者自定义删除 2. aliyun代码看到的一个对象正好符合上述需求 出处是aliyun sdk core jar包的一个类。感兴趣可以去下载下jar查看 下面是源码#xff1a; package com.aliyuncs.policy.…1. 功能 map 线程安全能够对存入的数据设置过期或者自定义删除 2. aliyun代码看到的一个对象正好符合上述需求 出处是aliyun sdk core jar包的一个类。感兴趣可以去下载下jar查看 下面是源码 package com.aliyuncs.policy.cache;import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.concurrent.BasicThreadFactory;public class ThrottlingPool {private static final MapString, Entity map new ConcurrentHashMap();private static final ScheduledExecutorService executor new ScheduledThreadPoolExecutor(1, (new BasicThreadFactory.Builder()).namingPattern(throttling-pool-%d).daemon(true).build());public ThrottlingPool() {}public static synchronized void put(String key, Object data) {put(key, data, -1);}public static synchronized void put(final String key, Object data, int expire) {remove(key);if (data ! null) {if (expire 0) {Future future executor.schedule(new Runnable() {public void run() {synchronized(ThrottlingPool.class) {ThrottlingPool.map.remove(key);}}}, (long)expire, TimeUnit.MILLISECONDS);map.put(key, new Entity(data, expire, future));} else {map.put(key, new Entity(data, expire, (Future)null));}}}public static synchronized Object get(String key) {Entity entity (Entity)map.get(key);return entity ! null ? entity.getValue() : null;}public static synchronized T T get(String key, ClassT clazz) {return (T)clazz.cast(get(key));}public static synchronized int getExpire(String key) {Entity entity (Entity)map.get(key);return entity ! null ? entity.getExpire() : 0;}public static synchronized Object remove(String key) {Entity entity (Entity)map.remove(key);if (entity null) {return null;} else {Future future entity.getFuture();if (future ! null) {future.cancel(true);}return entity.getValue();}}public static synchronized int size() {return map.size();}public static synchronized void clear() {for(Entity entity : map.values()) {if (entity ! null) {Future future entity.getFuture();if (future ! null) {future.cancel(true);}}}map.clear();}public static synchronized MapString, Entity getPool() {return map;}private static class Entity {private Object value;private int expire;private Future future;public Entity(Object value, int expire, Future future) {this.value value;this.expire expire;this.future future;}public Object getValue() {return this.value;}public int getExpire() {return this.expire;}public Future getFuture() {return this.future;}} }2. 但是有个问题如果数据量大且都设置有过期时间容易过期不及时单线程处理不过来 3. 下面代码采用延迟队列一版 import java.util.concurrent.*;public class ThrottlingPool {private static final ConcurrentHashMapString, Object map new ConcurrentHashMap();private static final DelayQueueDelayedCacheEntry delayQueue new DelayQueue();private static final ExecutorService executor Executors.newSingleThreadExecutor(r - {Thread t new Thread(r);t.setDaemon(true);return t;});public static void put(String key, Object data, long expireMs) {long expirationTime System.currentTimeMillis() expireMs;delayQueue.removeIf(entry - entry.getKey().equals(key));map.put(key, data);delayQueue.offer(new DelayedCacheEntry(key, expirationTime));}public static Object get(String key) {return map.get(key);}public static void remove(String key) {map.remove(key);}public static int size() {return map.size();}// 启动一个后台线程处理过期任务static {executor.execute(() - {while (!Thread.currentThread().isInterrupted()) {try {DelayedCacheEntry entry delayQueue.take(); // synchronized (ThrottlingPool.class) {map.remove(entry.getKey()); // }} catch (InterruptedException ex) {ex.printStackTrace();Thread.currentThread().interrupt();break;}}});// 钩子Runtime.getRuntime().addShutdownHook(new Thread(() - {executor.shutdown();})); // Thread cleanupThread new Thread(() - { // while (true) { // try { // DelayedCacheEntry entry delayQueue.take(); // synchronized (ThrottlingPool.class) { // map.remove(entry.getKey()); // } // } catch (InterruptedException e) { // Thread.currentThread().interrupt(); // break; // } // } // }); // cleanupThread.setDaemon(true); // cleanupThread.start();}private static class DelayedCacheEntry implements Delayed {private final String key;private final long expirationTime;public DelayedCacheEntry(String key, long expirationTime) {this.key key;this.expirationTime expirationTime;}Overridepublic long getDelay(TimeUnit unit) {long diff expirationTime - System.currentTimeMillis();return unit.convert(diff, TimeUnit.MILLISECONDS);}Overridepublic int compareTo(Delayed o) {return Long.compare(this.expirationTime, ((DelayedCacheEntry) o).expirationTime);}public String getKey() {return key;}}} 4.本人水平有限如有问题欢迎指正
http://www.zqtcl.cn/news/751711/

相关文章:

  • 网站搜索功能如何实现网络培训学习心得体会
  • 网站设计方案书ppt网站展示型推广
  • 中国建设注册管理中心网站首页大连地区建设网站
  • 广州致峰网站建设藁城网络推广
  • 怎么做免费个人网站wordpress dux 5.3
  • 手机触屏版网站网站功能介绍
  • 商场设计案例青岛百度快速排名优化
  • 制作网站要步骤湖北省建设厅网站上岗证查询
  • 网站建设制作公司都选万维科技制作网站需要注意什么
  • jsp小型网站开发wordpress微博插件
  • app充值网站开发怎么去做网站
  • 合肥建站网站模板word上下页纸张方向
  • 大学跳蚤市场网站建设哈尔滨网站建设
  • 网站开发合同中的知识产权条款怎么给公司建网站
  • 网站代维护wordpress 主题中心
  • 中铁广州建设有限公司网站临安做企业网站的公司
  • 国内可访问的海外网站和应用重庆好玩还是成都好玩
  • 定制开发小程序天津做网站优化的公司
  • 公司网站首页怎么做在线二级域名子域名查询
  • 淮南网站优化公司国内什么网站用asp.net
  • 做数据网站带网站的图片素材
  • 大方县住房城乡建设局网站wordpress 连接flickr
  • 国家建设部网站倪虹邢台新闻最新事件
  • 杭州网站 建设广州金将令做网站怎么样
  • 苏州科建设交通学院网站地方网站类型
  • 怎样做投资理财网站城乡建设部网站第35号令
  • 南昌集团网站建设wordpress去掉rss订阅
  • 郑州做网站的外包公司有哪些宁波 电商平台网站建设
  • 网站平台开发多少钱wordpress文章展示
  • 汕尾市企业网站seo点击软件建设一个网站的步骤有哪些