0

what is the difference between calling thread.start() and thread.run()? thread.start() will invoke the run() method and also the threading. Can we achieve multithreading by just calling the thread.run() ? Because i saw some examples in other software and doubt by just calling .run() it will spawn another thread.

hades
  • 4,294
  • 9
  • 46
  • 71
  • 2
    http://stackoverflow.com/questions/8579657/java-whats-the-difference-between-thread-start-and-runnable-run – dogant May 18 '15 at 06:57
  • is there in any circumstances we should call .run() only? – hades May 18 '15 at 06:59
  • If you want it to run on the calling thread. But then you probably didn't want a thread/runnable. – Luke May 18 '15 at 07:00
  • @user3172596 - There is just one circumstance - *when you want to verify that `run()` doesn't run in a seperate thread if called explicitly* :) – TheLostMind May 18 '15 at 07:00
  • @luke so by that means, by just calling .run() it actually wont spawn a thread? – hades May 18 '15 at 07:01
  • Nup. [more characters to reach the minimum comment length] – Luke May 18 '15 at 07:03
  • The separate start() and run() methods in the Thread class provide two ways to create threaded programs. The start() method starts the execution of the new thread and calls the run() method. The start() method returns immediately and the new thread normally continues until the run() method returns. The Thread class' run() method does nothing, so sub-classes should override the method with code to execute in the second thread. If a Thread is instantiated with a Runnable argument, the thread's run() method executes the run() method of the Runnable object in the new thread instead. – gtzinos May 18 '15 at 07:07

0 Answers0