diff --git a/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java b/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java index af0ad68a219..77c69d0d89f 100644 --- a/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java +++ b/src/main/java/org/springframework/samples/petclinic/errors/MonitorService.java @@ -9,8 +9,7 @@ import java.util.InvalidPropertiesFormatException; -@Component -public class MonitorService implements SmartLifecycle { +@Componentpublic class MonitorService implements SmartLifecycle { private boolean running = false; private Thread backgroundThread; @@ -48,30 +47,34 @@ public void start() { // Start the background thread backgroundThread.start(); System.out.println("Background service started."); - } - - private void monitor() throws InvalidPropertiesFormatException { - Utils.throwException(IllegalStateException.class,"monitor failure"); - } - + }/** + * Monitors the system state. This method is intentionally designed to throw an + * IllegalStateException as a demonstration feature to simulate monitoring failures. + * + * @throws InvalidPropertiesFormatException if properties are invalid + * @throws IllegalStateException intentionally thrown to demonstrate error handling + */ +private void monitor() throws InvalidPropertiesFormatException { + Utils.throwException(IllegalStateException.class,"monitor failure"); +} - @Override - public void stop() { - // Stop the background task - running = false; - if (backgroundThread != null) { - try { - backgroundThread.join(); // Wait for the thread to finish - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - System.out.println("Background service stopped."); - } +@Override +public void stop() { + // Stop the background task + running = false; + if (backgroundThread != null) { + try { + backgroundThread.join(); // Wait for the thread to finish + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + System.out.println("Background service stopped."); +} - @Override - public boolean isRunning() { - return false; - } +@Override +public boolean isRunning() { + return false; } +} \ No newline at end of file