execute a method only if the time is elapsed without using timer in java -


i want execute method in class every day once . if in day executed return or else execute method.

i want know happens if exit code running in background?

assuming you know how schedule task run daily trick becomes knowing if task has run in day without being prompted schedule.

for desired behavior need save time-stamp (either variable in java environment or file on disk) of recent run, checking before updating , executing function.

some psuedocode:

static bool timemanager(){    currenttime = getcurrenttime()    timestamp = gettimestamp()    if(currenttime - timestamp > 1day-afewminutes){         updatetimestamp(currenttime)         return true    }else{         return false    } } void jobwrapper(){     if timemanager(){         dothejob()     }else{         log("skipping job @ "+currenttime+" because job ran "+lasttime)     } } 

edit: rollback pointed out race condition put time manager in static method. realized rounding second might bone figured subtract few minutes whole day avoid tasks scheduled on 24 hour intervals blocking each-other due rounding...


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -