what will happen if we directly call run method? what will happen if we directly call run method? multithreading multithreading

what will happen if we directly call run method?


The run method is just another method. If you call it directly, then it will execute not in another thread, but in the current thread.

Here's my test TestRunnable:

class TestRunnable implements Runnable{   public void run()   {      System.out.println("TestRunnable in " + Thread.currentThread().getName());   }}

Output if only start is called:

TestRunnable in Fred

Output if only run is called:

TestRunnable in main

If start isn't called, then the Thread created will never run. The main thread will finish and the Thread will be garbage collected.

Output if neither is called: (nothing)


If you call start method then a separate thread will be allocated to execute the run method, means you achieve multi threading . But when you call run method directly then it becomes a normal method and main method itself will execute the run method , means no multi threading.