I am trying to figure out how Thread.sleep
works, so I create the following piece of code:
public static void main() {
Runnable runnable = new Runnable() {
public void run() {
try {
Thread.sleep(1000);
System.out.println("Middle");
} catch (InterruptedException e) {
}
}
};
System.out.println("Before");
Thread t2 = new Thread(runnable);
t2.start();
System.out.println("After");
However, it only prints Before
and After
in the console and skips the Middle
.
So I am wondering whether this Thread.sleep will break the Runnable part??