• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Thread's run() not running

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pardon my replication; I've posted a variant of this question on this board before, but now I understand the nature of my problem better, thus this post.
Basically, I've got a program which creates a new thread from a class that extends Thread. The program instantiates an object of that class (successfully -- everything in the constructor works OK), and then calls objectName.start().
For some reason, the run() method of the class is not executed at that point. I've double-checked that it's not some programming error in the method by making run()'s first action a simple System.out.println("Running..."); call, which should show up regardless of what else is going on in the method. The rest of the main program, which calls this class, continues to execute after calling objectName.start(), and has no apparent problems.
FYI, I'm using JDK 1.2 under Linux Emulation on OpenBSD 2.9. The same problem has occured under JDK 1.2 on Win98/2000 as well, so I doubt it's the OS.
Thanks,
Alex Kirk
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex,
Paste some of your code here. It will be easier to analyze your problem if we had some sample code to review.
Thanks,
-Peter
 
author
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alex Kirk:
Basically, I've got a program which creates a new thread from a class that extends Thread. The program instantiates an object of that class (successfully -- everything in the constructor works OK), and then calls objectName.start().
For some reason, the run() method of the class is not executed at that point...
Thanks,
Alex Kirk


A possible cause of this is having a slightly-wrong method signature for run. It must be "public void run()" exactly. Otherwise the run method in Thread - which does nothing - will be inherited.

Use javap on your class and be sure it has "public void run()" listed as a method:
<pre>ian$ javap java.lang.Thread | grep run
public void run();
ian$ cd $js/webserver/
ian$ jikes *.java
ian$ javap Handler | grep run
public void run();
ian$ </pre>
--
Ian Darwin
Author, Java Cookbook
P.S. Greetings fellow OpenBSD user!
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it is "public void run()"...but I'll let you look at what's going on here:

Hopefully that will help.
Alex
[This message has been edited by Cindy Glass (edited September 28, 2001).]
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of those println()s have you seen messages from on the screen durring a run? Have you seen "Gnutonic 0.1 at your service" printed out, for example?
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I launch, I see this:
Attempting to connect socket to port 7334...
Connected to socket: port 7334
Gnutonic 0.1 at your service
The first two lines are from connectionManager's constructor, which goes out and grabs a socket to communicate on.
Alex
 
James Gray
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, how about inserting a Thread.sleep(2000); line, right after that "at your service" println() and then telling me if you see any different output? What I'm mainly getting at here is what is that start thread doing after it gets the show up and running?
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex,
Let's see the entire connectionManager class or at least the c'tor too.
BTW, can you format your code so that it's more readable? Take a look at the FAQ to learn how.
Thanks,
-Peter
[This message has been edited by Peter Tran (edited September 26, 2001).]
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better yet, go to www.schnarff.com/gnutonic/, and you can see my code there. You'll be interested in connectionManager.java and runGnutonic.java.
Alex
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or even www.schnarff.com/gnutonic (as in without the comma that makes you get a 404).
Alex
 
James Gray
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which println()'s for Connection Manager's constructor are showing up in a sample run? Could you please post a sample run?
 
James Gray
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to download and run the code, but ran into an exception shown below:
Exception in thread "main" java.lang.NullPointerException
at Filelist.getFiles(Filelist.java:14)
at configReader.makeFileList(configReader.java:25)
at runGnutonic.main(runGnutonic.java:19)
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex,
Your connectionManager class run() method is okay. Are you running on a single CPU box? I think your running thread is getting blocked in the processing of the BufferedReader(). I'm running on a dual processor box, so it's running fine for me.
-Peter
 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is on a single-CPU box. How would I be blocked by the BufferedReader call?
FYI, this is what prints out when I run it:
Attempting to connect socket to port 7334...
Connected to socket: port 7334
Gnutonic 0.1 at your service

Alex
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic