1 28 29 package com.caucho.server.thread; 30 31 import com.caucho.util.Alarm; 32 import com.caucho.util.CacheListener; 33 34 54 public class TimedItem { 55 private long expireInterval; 56 57 private long createTime; 58 private Object value; 59 60 65 public TimedItem(long expireInterval) 66 { 67 this.expireInterval = expireInterval; 68 } 69 70 73 public long getExpireInterval() 74 { 75 return expireInterval; 76 } 77 78 81 public void setExpireInterval(long expireInterval) 82 { 83 this.expireInterval = expireInterval; 84 } 85 86 89 public void put(Object value) 90 { 91 createTime = Alarm.getCurrentTime(); 92 this.value = value; 93 } 94 95 98 public Object get() 99 { 100 if (Alarm.getCurrentTime() < createTime + expireInterval) 101 return value; 102 else { 103 Object v = value; 104 value = null; 105 106 if (v instanceof CacheListener) 107 ((CacheListener) v).removeEvent(); 108 109 return null; 110 } 111 } 112 } 113 114 115 | Popular Tags |