As I understand it, you want your task to start every 60 seconds.  Sometimes
that task will take 1 seconds to run, sometimes more.

So, you start at 1:00:00 (HH:MM:SS) and the task runs 10 seconds.  Subtract
the old time from the new time and subtract that from 60 (your interval).
This leaves you 50...the length of delay THIS period and issue your delay
job.  Next period, same game but perhaps you only delay 20 seconds.

You will also have to be careful of the situation where your delay time ends
up negative. Eg: The task ran longer than 60 seconds.

This is the most efficient in terms of system resources. 

Your other option would be to just submit a job to a dedicated single
threaded job queue every 60 seconds to run your task.  Yes.  You'll waste
some system resources.  But in the grand scheme of things, do you care?

If this is something that is part of a packaged solution, I've no doubht
that I'd use the first and more elegant solution.  But if this is strictly
an in-house thing, I'd probably go the second and easier route.

Bob

> -----Original Message-----
> From: c400-l-bounces+bob=cstoneindy.com@xxxxxxxxxxxx [mailto:c400-l-
> bounces+bob=cstoneindy.com@xxxxxxxxxxxx] On Behalf Of Jevgeni Astanovski
> Sent: Thursday, November 03, 2005 10:35 AM
> To: C programming iSeries / AS400
> Subject: RE: [C400-L] What is a technique to start a program periodically?
> 
> 
> I've asked this question once last year and got some proposals.
> Letter below describes more or less these possibilities.
> 
> There was also Simon Coulter's comment:
> 
> >Surely it would be better to start the program once and have it sleep
> >for n seconds between processing. That would avoid the overhead of
> >starting umpteen jobs as well as make it easier to locate problems.
> 
> But the problem is (I understood it now :-(((), that most of these are not
> what I've been looking for....
> 
> Imagine you need to START a process every minute, that is
> ......
> 7:00:00
> 7:01:00
> 7:02:00
> 7:03:00
> ......
> 
> And the process itself can take from 1 second to say 50 seconds -
> unpredictable.
> Both methods (1) and (2) does not do the job at all - as obvious as it is.
> I need to guarantee, that the process is started with a fixed frequency,
> and the proposed guarantees, that system will rest guaranteed amount of
> time between process executions.
> 
> The only method, that actually does the job is (3), when I have an upper
> level C(L) program, that submits my process every fixed period.
> But Simon says, that from the system point of view it is not very good.
> 
> Are there any other possibilities, or number (3) is the only one?
> 
> Jevgeni.
> 
> 
> > -----Original Message-----
> > From: Svensson, Joakim [mailto:joakim.svensson@xxxxxxxxxxxxx]
> > Sent: Friday, December 17, 2004 9:54 AM
> > To: C programming iSeries / AS400
> > Subject: RE: [C400-L] What is a technique to start a program
> > periodically?
> >
> >
> >
> > Hmm, well, I actually did write a response but our web-mail
> > client seems
> > to have kept all the text... The text you see is added to all outgoing
> > mail totally out of my control.
> > Back to my answer:
> >
> > You have several options to accomplish what you need:
> >
> > 1. Use a simple delay in a loop in your program.
> > C-pseudo code
> >
> > do {
> > ...stuff...
> > system("DLYJOB (60)");
> > } while (break_condition)
> >
> > 2. Use a time out on a data queue. This is nice since you can control
> > the program termination externally, by sending something via the data
> > queue and since it's consuming close to zero system resources.
> >
> > timeout = 60;
> > do {
> > ...stuff...
> > ReceiveFromDataqueue (myqueue, mydata, timeout);
> > } while (mydata <> "BREAK")
> >
> > 3. As suggested you can have another job submitting your program every
> > 60 seconds, or you can do it from your program, but both options are
> > inefficient from a system point of view.
> >
> >
> > All these options would in practice require you to execute
> > your program
> > in a new job queue, or else your program would hog QBATCH all day long
> > which normally is not accepted.
> >
> >
> > Joakim
> > ------------------------------------
> > Svensson, Joakim
> > Capgemini, Sweden
> > Certified Enterprise Architect / Principal
> > Joakim.Svensson@xxxxxxxxxxxxx
> > Sweden
> > ------------------------------------
> >
> > -----Original Message-----
> > From: c400-l-bounces+joakim.svensson=capgemini.com@xxxxxxxxxxxx
> > [mailto:c400-l-bounces+joakim.svensson=capgemini.com@xxxxxxxxxxxx] On
> > Behalf Of Peter Grace
> > Sent: den 16 december 2004 20:07
> > To: C programming iSeries / AS400
> > Subject: Re: [C400-L] What is a technique to start a program
> > periodically?
> >
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > It's a new kind of e-mail where only the person it's addressed to can
> > actually see the message!
> >
> > OK, maybe not.  But it makes you wonder! <puts on tinfoil hat>
> >
> > Pete
> >
> >
> >
> > Jevgeni Astanovski wrote:
> > | Hm-m-m....
> > | Does it really contain anything confidential?
> >
> > /------------------------------------------------\
> > |Peter Grace                  Phone: 484-875-9462
> > |Technology Analyst             Fax: 484-875-9461
> > |RealTime Technologies, Inc.
> > |835 Springdale Drive, Suite 101
> > |Exton, PA  19341
> > \------------------------------------------------/
> >
> > This message contains information that may be privileged or
> > confidential and is the property of the Capgemini Group. It
> > is intended only for the person to whom it is addressed. If
> > you are not the intended recipient,  you are not authorized
> > to read, print, retain, copy, disseminate,  distribute, or
> > use this message or any part thereof. If you receive this
> > message in error, please notify the sender immediately and
> > delete all  copies of this message.
> >
> >
> > _______________________________________________
> > This is the C programming iSeries / AS400 (C400-L) mailing list
> > To post a message email: C400-L@xxxxxxxxxxxx
> > To subscribe, unsubscribe, or change list options,
> > visit: http://lists.midrange.com/mailman/listinfo/c400-l
> > or email: C400-L-request@xxxxxxxxxxxx
> > Before posting, please take a moment to review the archives
> > at http://archive.midrange.com/c400-l.
> >
> >
> 
> --
> This is the C programming iSeries / AS400 (C400-L) mailing list
> To post a message email: C400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/c400-l
> or email: C400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/c400-l.



This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact [javascript protected email address].