How do I get my Java object to stop resetting its creation date to the current date? -


this basic, can't figure out why keeps resetting creation date. i'm using simple expiration cache on object. if expired, create new object. if isn't, use 1 exists. however, every time go check creation date on object, current date.

public class myobjectimpl implements myobjectinterface {      private static final long serialversionuid = -3542728718515350246l; // auto generated eclipse...      public myobjectimpl() {         this.creationdate = new date().gettime();     }      public boolean hasexpired(biginteger millesecondstoexpiration) {         if (millesecondstoexpiration == null) {             millesecondstoexpiration = new biginteger("2592000000"); // 30 days         }         if (getcreationdate() + millesecondstoexpiration.longvalue() < new date().gettime()) {             return true;         } else {             return false;         }     }      private long creationdate;      public long getcreationdate() {         return this.creationdate;     } } 

here how call it:

myobjectinterface myobject = (myobjectinterface)session.getattribute("my_object");  if (myobject == null || (myobject != null && myobject.hasexpired(null))) {     session.setattribute("my_object", new myobjectimpl()); } 

hasexpired returns true young objects, wrong way around:

if (getcreationdate() + millesecondstoexpiration.longvalue() < new date().gettime()) {         return true;     } else {         return false;     } 

so recreate object each time.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -