Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

about threads  RSS feed

 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a doubt on threads and run() method.

here is my code

PROGRAM:
___________________________________________________________________

public class threaddemo extends Thread{

public void run()
{
System.out.println("bhanu");
}

public static void main(String[] args) {
//Runnable b=new Thread();
threaddemo c=new threaddemo();
c.start();



}

}
___________________________________________________________________

here with out calling run method it is displaying the following output

OUTPUT:

______________________________________________________________________

bhanu

______________________________________________________________________


how it is executing.where it is calling the run method.
there should be some code in Thread class's start() method.

here is the start() procedure body defines in Thread class.

START() PROCEDURE BODY:

_____________________________________________________________________

public synchronized void start() {
if (started)
throw new IllegalThreadStateException();
started = true;
group.add(this);
start0();
}

private native void start0();

_____________________________________________________________________


where can i get the implementation of native method start();

can anybody please explain me this clearly.
 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You dont need to write a start() method in the thread class, just make sure it implements runnable or extends thread (and has a run method).

When you call someThread.start() from your main class; the instance of someThread will 'come alive', and whatever is in the run method of someThread will execute.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!