Running an application automatically every day

我与影子孤独终老i 提交于 2019-12-13 19:06:43

问题


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 *


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/25205685/running-an-application-automatically-every-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!