Wie kann ich einige Prozesse im Hintergrund mit Spring Boot ausführen? Dies ist ein Beispiel für das, was ich brauche:run Prozess im Hintergrund mit Spring Boot
@SpringBootApplication
public class SpringMySqlApplication {
@Autowired
AppUsersRepo appRepo;
public static void main(String[] args) {
SpringApplication.run(SpringMySqlApplication.class, args);
while (true) {
Date date = new Date();
System.out.println(date.toString());
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Vielen Dank, ich möchte die FixedRate in die Unendlichkeit ändern –
Warum würden Sie das tun? In deinem Beispiel könntest du die Rate auf 3000 setzen, also brauchst du nicht die TimeUnit.SECONDS.sleep (3); nicht mehr, da Ihre Methode alle 3000 ms ausgeführt wird. –