Why can’t we call run() method directly in Java?

This “Why can’t we call run() method directly in Java?” post is giving explanation about why we need to depends on start() method to start the thread instead of calling run() method directly in java application.

core-java-online-training-2

Why run() method cannot throws InterruptedException?

  • Java syntactical rule describes, it is mandatory to override the method in the sub class how it has specified in its super-class.
  • run() method is the overridden method, hence it is not possible to modify its prototype.

 

Why can’t we call run() method directly ?

  • It is allowed to call run() method explicitly instead of start() method.
  • If we invoke run() method directly, the logic executes only in existing thread(sequential flow).
  • Pre-defined start() method is having logic to allocate the separate thread space and executes run() method logic in the allocated space.
  • As a programmer we can’t allocate the thread space explicitly, hence we depends on start() method to create threads in application.

run() method doesn’t have thread creation logic



core-java-online-training-2

Share this