Running an application automatically every day

2019-08-01 01:38发布

I have an application that tests web services. And I want to run this application every day at 6 pm.

I wonder if it is possible to do this automatically?

*For information: this application is developed with Java, JUnit parameterized tests, maven..., OS: Windows 7 *

2条回答
手持菜刀,她持情操
2楼-- · 2019-08-01 02:17

You can create schedule task in windows and cron job in UNIX to trigger your application which test web services.

查看更多
We Are One
3楼-- · 2019-08-01 02:28

You can do something like this

ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int delay = hour < 18 ? 18-hour : 18- (hour-18);
System.out.println("Current Hour : "+hour+"\t"+"Delay For Next Mail: "+delay);
executor.scheduleAtFixedRate(new Runnable() {
     @Override
     public void run() {
          System.out.println("run invoked");
             //do something
            }
        }, delay , 24, TimeUnit.HOURS);

Provided the server is up and running.

First create an instance of ScheduledExecutorService which provides the method

public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                                  long initialDelay,
                                                  long period,
                                                  TimeUnit unit);

Accordingly calculate the delay ,period and the TimeUnit and the task to be executed

查看更多
登录 后发表回答