Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding thread run method

 
rajareddy annavaarm
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant we call run method in thread class directly?why we are calling it indirectly by start method?
 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajareddy,
When you call the run method directly a separate call stack is not created and it runs as a part of the same call stack from the method which it is called.Eventually it doesnt run concurrently with other threads.

regards,
Raja
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the answer is that you can call run() method, just like any other method. But that runs it in the current thread. If you want to run it in another thread, you must use the API of Thread class to start a new thread, which will then call run() in the new thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic