Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Recurring event

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I want my application to support recurring events.
EX: The event will be repeated every 24 hours : 2021-01-01 22:40:32  the new event start at 2021-01-02 22:40:00
I think the mistake is at  Calendar c = Calendar.getInstance();
       c.setTime(this.dataP);
       if (this.dataP.after(getDataInceput())) {
           c.add(Calendar.HOUR, numarOre);
       }


 
Marshal
Posts: 76082
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't use Date, nor Calendar. Use the datatypes described in this tutorial.
Will you be running your application continuously? Consider a java.util.Timer, or use a system utility like cron.
 
Saloon Keeper
Posts: 25823
184
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Andrei!

While he basic Java systems has become a lot more extensive in recent years, I think probably that the Quartz Scheduler might be better suited. It's a third-party library that can is very flexible in dealing with recurring events and events on a fixed schedule. If you're using the Spring Framework, it has a scheduling module, also, including the ability for Quartz to be managed by Spring.

Also, I'm assuming that your app will be operating 24 hours a day. If you actually just need to run a Java program at a given time and/or on given days, you can use the cron facility that's standard with Unix/Linux or the Windows Scheduler on Windows.
 
Master Rancher
Posts: 4833
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also posted here: https://www.dreamincode.net/forums/topic/421013-recurring-event/

Please read:  https://coderanch.com/wiki/660346/Wiki/Forthright-Cross-Posting-Sites
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you find a solution for this code?
 
Campbell Ritchie
Marshal
Posts: 76082
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

AD hasn't posted for over a year, so I wouldn't expect him to answer. Sorry.
 
Campbell Ritchie
Marshal
Posts: 76082
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How frequently would you like your app to respond, and how long will it run altogether?
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic