[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

scheduler java program

Hi everybody, This is my problem. I want to make a java program that run all time in server. But when in the midnight (00:00:00 AM) I want my program run some jobs like open file and update another file. My problem is how to make that shecduler program in java.

               
0
Meidi
Asked:
Meidi
1 Solution
 
nil_dibCommented:
Maybe there are smarter ways to do this ... but htat one works fine:


public class DateChecker extends Thread
{
    java.util.Date _date = null;
    public void run()
    {
        while(true)
        {
            _date = new java.util.Date();
            if( 0 == _date.getMinutes() && 0 == _date.getHours())
            {
                // its 0:00
                // do something
               
                System.out.println ( "it is 0:00 !" );
            }
            try
            {
                // check every 30 sec.
                this.sleep(30000);
            }
            catch (Exception e) {};          
            Thread.yield();
        }
    }


    public static void main(String[] args)
    {
        new DateChecker();
    }

    public DateChecker()
    {
        start();
    }
}

nil_dib
0
 
jsridharCommented:
u can also use the javax.swing.Timer class.

js.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now