Thread thread = new Thread(() -> { while (!Thread.interrupted()) { System.out.println("Thread is running"); } System.out.println("Thread interrupted"); }); thread.start(); // interrupt the thread after 2 seconds Thread.sleep(2000); thread.interrupt();In this example, we create a new thread that runs in a while loop until it is interrupted. The interrupt status is checked using the `interrupted()` method. Once the thread is interrupted, it prints a message and stops running. The package library used for this example is `java.lang`.