// --- Call the file copying method.
} else {
System.out.println("NO REMOTE FILE FOUND");
}
} else {
System.err.println("PLEASE CHECK DIRECTORY [" + remote.getAbsolutePath() + " OR/AND"
+ local.getAbsolutePath() + "] existence");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class ScheduledExample {
private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
private static final int LOCAL_INTERVAL = 5, COPY_INTERVAL = 2;
private static final String REMOTE_DIR = "REMOTE", LOCAL_DIR = "LOCAL";
public static void main(String args) {
Runnable localService = new LocalService(LOCAL_DIR);
Runnable remoteService = new CopyService(REMOTE_DIR, LOCAL_DIR);
try {
executor.scheduleWithFixedDelay(localService, 0, LOCAL_INTERVAL, TimeUnit.SECONDS);
executor.scheduleWithFixedDelay(remoteService, 0, COPY_INTERVAL, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}
作者:沉默是金