954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

a thread challenge-----

can we run a run() method with out using a start() method in a program?

public class A extends Thread
{
public void run()
{

System.out.println(" i will execute any way");

}

public static void main(string args[])
{

A a=new A();

a.run(); // no start method

}
}

satish.paluvai
Light Poster
45 posts since Mar 2007
Reputation Points: 9
Solved Threads: 1
 

> can we run a run() method with out using a start() method in a program?
Yes, but it won't work the way you expect it to work.

Calling the run() method directly would be like calling a normal method. No thread of execution is created, no concurrency. On the other hand, calling the start method spawns a new thread of execution which can execute concurrently with other threads by executing the run() method.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
Yes, but it won't work the way you expect it to work.



it will work!!! but only as a method, not thread. It won't run simultaneously :)

ProgrammersTalk
Junior Poster in Training
84 posts since Jun 2007
Reputation Points: 21
Solved Threads: 7
 
it will work!!! but only as a method, not thread. It won't run simultaneously :)

If you read his thread,
that is exactly what he said.

;-)

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

If you read his thread, that is exactly what he said.

;-)



haha sorry, I just realized that once I re read it again... my bad... XD

ProgrammersTalk
Junior Poster in Training
84 posts since Jun 2007
Reputation Points: 21
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You