• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Recurring event

 
Greenhorn
Posts: 1
  • 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: 72407
315
  • 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: 23409
159
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: 4250
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
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic