Problem in executing multithreaded program

V

vaibhav

Hi all,
I have a java program with 3 thread, thread1 , thread2 ,
thread3. When I call thread1.run() , thread2.run() and
thread3.run() .. the execution of thread1 and thread2 start but
thread3 does not run.
Thread1 contains linked list handling , Thread2 contains
execution of "tcpdump" command and Thread3 contains execution of
"ping" command. Can anybody tell me why my thread3 is not running ??
 
J

John B. Matthews

rossum said:
Is the problem the order of the threads? What happens if you fire
them off in a different order? 321, 132, 213 etc.

Is the problem with the ping command? Change thread3 to display
"Hello World" on the console instead of pinging. Does that help?

Try to run ping alone from an unthreaded program. Does it work?

Is the problem with the number of threads. Cut out thread1 and
thread2, just run thread3. Does that work? What about with just two
threads? Four threads?

vaibhav: In addition to the systematic approach suggested by rossum,
verify that thread3 isn't terminating abruptly by providing an
UncaughtExceptionHandler:

<http://java.sun.com/javase/6/docs/api/java/lang/Thread.html>

More discussion may be found here:

<http://www.ibm.com/developerworks/java/library/j-jtp0924.html>
 
L

Lew

vaibhav said:
I have a java [sic] program with 3 thread, thread1 , thread2 ,
thread3. When I call thread1.run() , thread2.run() and
thread3.run() .. the execution of thread1 and thread2 start but
thread3 does not run.

<http://sscce.org/>

Patricia said:
Do you literally mean you are calling e.g. thread2.run(), or are you
calling thread2.start(), which creates a new thread and invokes the
Thread object's run() method in it?

That's exactly the sort of question an SSCCE can answer, and this sort of
vague, "I have a problem, what's the solution?" type of post cannot.

<http://sscce.org/>
<http://sscce.org/>
<http://sscce.org/>
 
M

markspace

vaibhav said:
Hi all,
I have a java program with 3 thread, thread1 , thread2 ,
thread3. When I call thread1.run() , thread2.run() and
thread3.run() .. the execution of thread1 and thread2 start but
thread3 does not run.
Thread1 contains linked list handling , Thread2 contains
execution of "tcpdump" command and Thread3 contains execution of
"ping" command. Can anybody tell me why my thread3 is not running ??


I have to answer what Lew said: We need real code to understand what
the problem is. There's no way to answer "why my thread3 is not
running" other than with "because you made a mistake."

Please post an SSCCE so we can answer your question properly.

http://sscce.org/
 
D

Daniel Pitts

Hi all,
I have a java program with 3 thread, thread1 , thread2 ,
thread3. When I call thread1.run() , thread2.run() and
thread3.run() .. the execution of thread1 and thread2 start but
thread3 does not run.
Thread1 contains linked list handling , Thread2 contains
execution of "tcpdump" command and Thread3 contains execution of
"ping" command. Can anybody tell me why my thread3 is not running ??
Well, for one thing you should call Thread.start() to start a thread.
Thread.run() won't actually start up a new thread, but simply run it in
the current thread.

If your tcpdump blocks until it receives information, then it will
prevent thread3 from ever starting.


Try using start() instead of run().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top