fork download
  1. class Example
  2. {
  3. public static void main (String[] args) throws java.lang.Exception
  4. {
  5. Thread t= new Thread(new Runnable() {
  6. @Override
  7. public void run() {
  8. System.out.println(Thread.currentThread().getName() + ": Running run");
  9. }
  10. });
  11. System.out.println(Thread.currentThread().getName() + ": Running main");
  12. System.out.println(Thread.currentThread().getName() + ": Calling t.start()");
  13. t.start();
  14. System.out.println(Thread.currentThread().getName() + ": Calling t.join() to wait for thread exit");
  15. try {
  16. t.join();
  17. } catch (InterruptedException ie) {
  18. System.out.println(Thread.currentThread().getName() + ": Calling got InterruptedException");
  19. }
  20. System.out.println(Thread.currentThread().getName() + ": Program complete");
  21. }
  22. }
  23.  
Success #stdin #stdout 0.1s 320896KB
stdin
Standard input is empty
stdout
main: Running main
main: Calling t.start()
main: Calling t.join() to wait for thread exit
Thread-0: Running run
main: Program complete