• Post Reply Bookmark Topic Watch Topic
  • New Topic

relation between start() & run() in thread

 
Mandar Khire
Ranch Hand
Posts: 572
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think/read, Every program import java.lang package which Provides classes that are fundamental to the design of the Java programming language.In java.lang package there is one interface called Runnable which description is "The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread."
The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments called run.
In this Interface Runnable there is method Run()
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
The general contract of the method run is that it may take any action whatsoever.
when we write public class t extends Thread {
Thread.java which we extend for class t, & in this Thread.java folowing code is written


/* from this i started thinking*/ So when we call t.start() it goes to if condition call start0(), then in start0() we call target.run(), target is our class t.
therefore When we start a thread by using t.start(), it knows that to execute run()method.
is my thinking & study is right?
[ July 14, 2008: Message edited by: Mandar Khire ]
 
Sid Murrey
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
start0() is a native method and not defined in this class definition.
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread started in wrong forum.
It should go some where else.
 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, when you call the start() method on an instance of a thread, whatever is in the the thread's run method will execute.

ie. You shouldn't calling the threads run() method directly.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you want it to be executed in the same thread
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Sudhir Nim is right: off to the Threads forum you go . . .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!