| Author |
Time Triggered events in Javascript
|
Pragnyan Dalei
Greenhorn
Joined: Dec 28, 2011
Posts: 11
|
|
Hi,
is it possible to write any time triggered funtionality in java script so that it will capture the system time and if it is 2pm it will show a message/send a mail to few persons/send a report via email...
|
 |
Saikat Roy Mahasay
Greenhorn
Joined: Jan 12, 2012
Posts: 10
|
|
Javascript has a setTimeOut method that can defer calling a method by certain ms. But I am not sure if it serves your purpose. Could you please provide some more detail? Will it run once and check the time on some event ( like onLoad, maybe? ) and alert if it is 2PM , (do nothing otherwise)? or you would rather like a program to silently check every 10 seconds and come to life at 2 PM?
For the first case, it is not very hard, you need to check the Date object in javascript.
If, however, it is the second case, you need to juggle some actions with setTimeOut. Recursion can be one way. The function start on an event (onLoad?) and check client system time (like the first one) and act if the proper time is obtained; otherwise set a timeout for itself to be run after some time.
-- by the way, I do not think Jobs Discussion is the right place for this query.
|
 |
Pragnyan Dalei
Greenhorn
Joined: Dec 28, 2011
Posts: 11
|
|
Saikat Roy Mahasay wrote:Javascript has a setTimeOut method that can defer calling a method by certain ms. But I am not sure if it serves your purpose. Could you please provide some more detail? Will it run once and check the time on some event ( like onLoad, maybe? ) and alert if it is 2PM , (do nothing otherwise)? or you would rather like a program to silently check every 10 seconds and come to life at 2 PM?
For the first case, it is not very hard, you need to check the Date object in javascript.
If, however, it is the second case, you need to juggle some actions with setTimeOut. Recursion can be one way. The function start on an event (onLoad?) and check client system time (like the first one) and act if the proper time is obtained; otherwise set a timeout for itself to be run after some time.
-- by the way, I do not think Jobs Discussion is the right place for this query.
Hi ,
thanks for your reply Saikat. I am developing one web application that will connect to Quality center and I need at a particular time of the day a report will be retrieved by connecting to Quality center and that report will be sent to few mail ids. will that be possible . I am using jsp and javascript for this web application.
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1351
|
|
Saikat Roy Mahasay wrote:-- by the way, I do not think Jobs Discussion is the right place for this query.
Pragnyan , Any harm in considering server time rather than client time?
|
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6371
|
|
show a message/send a mail to few persons/send a report via email...
That seems like an awful lot of work for JS. Can you trigger a servlet instead ? Is it necessary to consider the client's time instead of the server's ?
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Pragnyan Dalei
Greenhorn
Joined: Dec 28, 2011
Posts: 11
|
|
|
yes I can use servlets. even I am using servlets for connecting to Quality center. I apologize i havent mentioned it... so can i do it through servlets.. if so in what way??
|
 |
Saikat Roy Mahasay
Greenhorn
Joined: Jan 12, 2012
Posts: 10
|
|
Well, your requirement sounds like an independent thing. It does not need to run in the webserver or the client.
How about writing a standalone java program, and schedule it using a system scheduler like cron? In that case you do not need to worry about checking the time.
|
 |
Pragnyan Dalei
Greenhorn
Joined: Dec 28, 2011
Posts: 11
|
|
|
I have no idea about cron. can you please explain me whta this is
|
 |
Pragnyan Dalei
Greenhorn
Joined: Dec 28, 2011
Posts: 11
|
|
|
Is it an API. that we can use in our java program?
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1351
|
|
Is it this.
|
 |
Saikat Roy Mahasay
Greenhorn
Joined: Jan 12, 2012
Posts: 10
|
|
No, cron is the task scheduler for the Unix like systems. http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5 In windows, I believe there's a job scheduler, but please look it up in the net.
Either way, the idea is to provide the OS with a program or a script, and some scheduling information. The OS will check the time, and at appropriate time call the program to execute. Even if your webserer is down, the cron scheduled program will run.
Hope this helps.
|
 |
Pragnyan Dalei
Greenhorn
Joined: Dec 28, 2011
Posts: 11
|
|
|
yeah Thanks Saikat . I will try these.
|
 |
 |
|
|
subject: Time Triggered events in Javascript
|
|
|