6 Replies Latest reply: Feb 21, 2008 7:06 PM by 807603 RSS

    problem of Thread constructors is before "start()"

    807603
      desired behaviour:
      prevent starting of a Thread before a critical a instance variable is defined.

      normally this happens in the constructor. however, this is the unchangeable flow control:
      (1) construct the Thread object.
      (2) calculate the critical instance variable.
      (3) start the Thread.

      if the thread starts without knowning the value calculated in step #2, then it cannot do anything useful.

      in my api, i can say "be careful not to start this thread until after invoking:
      *public void setCriticalValue(int x);*

      how can i +force+ a developer that uses this class to assign the critical instance variable a value before starting the thread? i think something like:

      {code}public void run() {
      if(this.criticalValue == null) { return; }
      ....
      }
      public void realStart(List x) {
      this.criticalValue = x;
      this.start();
      }{code}
      would confuse the heck out of a developer and is worst solution.

      thanks.