Error question.


R. Clayton (rclayton@monmouth.edu)
(no date)


findbugs produces the following output

  SC: HoneyMain.<init>(int,int,int) invokes java.lang.Thread.start()
  SC: HoneyMain.<init>(int,int,int) invokes java.lang.Thread.start()

for the input (I've removed some of the non-thread code)

  public class HoneyMain {

      public HoneyMain(int potCap, int numBees, int numLoops) {

          int bearLoops = (numBees * numLoops) / potCap;
          HoneyPot h = new HoneyPot(potCap);

          for (int i = 1; i <= numBees; ++i) {
              BeeRunnable br = new BeeRunnable(h, i, numLoops);
              Thread t = new Thread(br);
              t.start();
          }

          BearRunnable br = new BearRunnable(h, bearLoops);
          Thread t = new Thread(br);
          t.start();
      }

      public static void main(String[] args) {

          int potCap = Integer.parseInt(args[0]);
          int numBees = Integer.parseInt(args[1]);
          int loops = Integer.parseInt(args[2]);

          HoneyMain hm = new HoneyMain(potCap, numBees, loops);
      }
  }

What does this problem mean? Why is it worth noting? Is there somewhere in
the documentation (not the code) where the errors are described in more detail?

I'm guessing the problem is calling threads in a constructor, which, owing to a
time-slicing scheduler, might give the threads a view of a class instance in a
inconsistently initialized state (perhaps not in this case, but in general).



This archive was generated by hypermail 2.0b3 on Tue Aug 12 2003 - 09:30:05 EDT