diff --git a/.gitignore b/.gitignore index 94b7950..5def27e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +out/ build classes .DS_Store @@ -7,4 +8,4 @@ classes .settings *.iml *.ipr -*.iws \ No newline at end of file +*.iws diff --git a/src/main/java/me/hatter/sample/Application.java b/src/main/java/me/hatter/sample/Application.java index 38e694c..7bf69fc 100644 --- a/src/main/java/me/hatter/sample/Application.java +++ b/src/main/java/me/hatter/sample/Application.java @@ -3,7 +3,9 @@ package me.hatter.sample; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; +@EnableScheduling @ComponentScan(basePackages = "me.hatter.sample") @SpringBootApplication public class Application { diff --git a/src/main/java/me/hatter/sample/common/misc/WatchFolder.java b/src/main/java/me/hatter/sample/common/misc/WatchFolder.java new file mode 100644 index 0000000..4b9431f --- /dev/null +++ b/src/main/java/me/hatter/sample/common/misc/WatchFolder.java @@ -0,0 +1,31 @@ +package me.hatter.sample.common.misc; + +import java.io.File; +import java.io.IOException; +import java.nio.file.*; + +public class WatchFolder { + public static void main(String[] args) throws IOException { + WatchService watchService = FileSystems.getDefault().newWatchService(); + Path directory = new File(".").toPath(); + + WatchKey watchKey = directory.register(watchService, + StandardWatchEventKinds.ENTRY_CREATE, + StandardWatchEventKinds.ENTRY_MODIFY, + StandardWatchEventKinds.ENTRY_DELETE + ); + while (true) { + for (WatchEvent event : watchKey.pollEvents()) { + WatchEvent pathEvent = (WatchEvent) event; + Path fileName = pathEvent.context(); + WatchEvent.Kind kind = event.kind(); + + System.out.println("[WatchFolder] " + kind + ", " + fileName); + } + boolean valid = watchKey.reset(); + if (!valid) { + break; + } + } + } +} diff --git a/src/main/java/me/hatter/sample/common/schedule/CustomScheduler.java b/src/main/java/me/hatter/sample/common/schedule/CustomScheduler.java new file mode 100644 index 0000000..a2ae23c --- /dev/null +++ b/src/main/java/me/hatter/sample/common/schedule/CustomScheduler.java @@ -0,0 +1,16 @@ +package me.hatter.sample.common.schedule; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +@Component +public class CustomScheduler { + @Scheduled(cron = "0/5 * * * * *") + public void run() { + System.out.println("[CustomScheduler] Time now is : " + + LocalTime.now().format(DateTimeFormatter.ofPattern("hh mm ss"))); + } +}