问题
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