public class MessageLoop implements Runnable {
  //Display a message, preceded by the name of the current thread
  static void threadMessage(String message) {
    String threadName = Thread.currentThread().getName();
    System.out.format("%s: %s%n", threadName, message);
  }
  public void run() {
    String importantInfo[] = {
      "Boi, boi, boi...",
      "Boi da cara preta,",
      "Pega este menino...",
      "Que tem medo de careta."
    };
    try {
      for (int i = 0; i < importantInfo.length; i++) {
        //Pause for 2 seconds
        Thread.sleep(2000);
        //Print a message
        threadMessage(importantInfo[i]);
      }
    } catch (InterruptedException e) {
      threadMessage("I wasn't done!");
    }
  }
  public static void main(String args[]) {
    (new Thread(new MessageLoop())).start();
  }
}
