• Realizing periodic interruptions in code execution

    From sandeep6699@yahoo.com@21:1/5 to All on Wed Jan 4 13:22:35 2017
    Hi netizens,

    I had posted a query on stackover regarding periodic interruptions in code execution (http://stackoverflow.com/questions/41459456/java-realizing-periodic-interruptions-in-code-execution/41460518). My query was as follows:
    "How to realize the following: After every 10 minutes interrupt your business logic and go to sleep for 5 minutes"

    My original query was Java specific and I got a great response for my query. Actually the response is language neutral, hence the posting to this newsgroup.

    Refactor the code so that it looks like this:

    Business-logic LOOP BEGIN
    Execute business logic
    Business-logic LOOP END


    Now to this, make the following changes:



    DEF WorkingInterval, SleepInterval, startTime

    startTime = currentTime()
    Business-logic LOOP BEGIN
    IF(currentTime() < startTime + WorkingInterval) Execute business logic
    ELSE BEGIN
    sleep(SleepInterval)
    startTime = currentTime()
    ELSE END
    Business-logic LOOP END



    I think the proposed solution is pretty elegant. Any other simple alternatives come to mind?

    Regards,
    SS

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)