2011년 3월 10일 목요일

java scheduler

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class BatchScheduler {

public ScheduledThreadPoolExecutor sch ;

public BatchScheduler() {
super();
sch = new ScheduledThreadPoolExecutor(2);
}

public void start() throws FileNotFoundException, IOException {

SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd", new Locale("KOREAN", "KOREA"));
String jobDate = formatter.format(new Date());

// from 0 second , interval 10 second
sch.scheduleAtFixedRate(new SendImage(jobDate), 0, 10, TimeUnit.SECONDS);
sch.scheduleAtFixedRate(new DeleteImage(jobDate), 0, 10, TimeUnit.SECONDS);

}

public void stop() {
sch.shutdown();
}

public static void main(String[] args) {
BatchScheduler t = new BatchScheduler();
try {
t.start();
} catch ( Exception e ) {
e.printStackTrace();
}
}

}

댓글 없음:

댓글 쓰기