This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads: Difference in calling run() and start()  RSS feed

 
C Halbe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that once a thread gets an ID it will not change until the thread is dead. But why does the ID change when we run the below code with start() and it does not change when we call the run() directly?



Please help me understand.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because when you call run() directly you aren't creating a new thread, you're just calling the run() method in the current thread. It's just a normal method, there's nothing stopping you calling it like any other method. Whereas calling start() will create a new thread and execute run() in that.
 
C Halbe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! Thanks.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!