944,158 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1047
  • Java RSS
Jul 15th, 2007
0

a thread challenge-----

Expand Post »
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

}
}
Similar Threads
Reputation Points: 9
Solved Threads: 1
Light Poster
satish.paluvai is offline Offline
45 posts
since Mar 2007
Jul 15th, 2007
0

Re: a thread challenge-----

> 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.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Jul 15th, 2007
0

Re: a thread challenge-----

Quote ...
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
Reputation Points: 21
Solved Threads: 7
Junior Poster in Training
ProgrammersTalk is offline Offline
83 posts
since Jun 2007
Jul 16th, 2007
0

Re: a thread challenge-----

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.

;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 16th, 2007
0

Re: a thread challenge-----

Quote ...
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
Reputation Points: 21
Solved Threads: 7
Junior Poster in Training
ProgrammersTalk is offline Offline
83 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Summing Issue from Array
Next Thread in Java Forum Timeline: First Attempt at Arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC