• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer That should never end and trigger daily

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a program which is having 2 timers which gets triggered 2 timeswhen ever the time occurs and every day when ever i start a program. Now i have a situation where i start the program only once and every day it has to trigger 2 times with out starting the appication every day .
The below is the program which is triggering :

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimerTiggerEvent {

public static void main(String[] args) {

Calendar c = Calendar.getInstance();
//c.set(Calendar.HOUR,22);
c.set(Calendar.HOUR_OF_DAY,15);
c.set(Calendar.MINUTE,41);
c.set(Calendar.SECOND,00);


Date timeToRun=c.getTime();
System.out.println("date="+timeToRun);

Timer timer = new Timer();

timer.schedule(new TimerTask() {
public void run() {
System.out.println("Hiiiii");
System.out.println(System.currentTimeMillis());
}
}, timeToRun);

c.set(Calendar.HOUR_OF_DAY,14);
c.set(Calendar.MINUTE,41);
c.set(Calendar.SECOND,00);


Date timeToRuns=c.getTime();
System.out.println("date="+timeToRun);


timer.schedule(new TimerTask() {
public void run() {
System.out.println("timeToRuns");
System.out.println(System.currentTimeMillis());
}
}, timeToRuns);

}

}


let me know what to do and what possibilities are there? any suggestions???
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should use another constructor of the Timer which allows you to set it as a deamon. Also, look at other schedule methods of Timer class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic