-1

Running the code:

Thread tt = new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        });
System.out.println(tt.getName());
tt.run();

I would expect to get:

Thread-0
Thread-0

But instead I get:

Thread-0
main

Why is that?

Johnny
  • 7,073
  • 9
  • 46
  • 72

1 Answers1

0

Your Thread's run method doesn't do anything. The Runnable's run method calls println, but in your code it's never run. Call start() on the thread not run()

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373