Why does my program run with strange order?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Why does my program run with strange order?

  1. #1
    Join Date
    Jul 2005
    Posts
    28

    Why does my program run with strange order?

    Could somebody please suggest me at what situation a progarm could run with the order that is not as it looks like.

    eg: When the code should run sequencely, it does not.

    In my case, I don't have many threads: I have a GUI and a main. The program will begin to run until it gets the GUI interface and then it stops to wait for me to press one button to continue. A lot of strange problems come out after that. This is one of it.

    I am not sure where my problem resides, but it starts to be strange near something like the following (when it prints something. )


    public void waitToStart(PrintWriter pW)throws IOException
    {
    while(!start){}
    startRun(pW);
    }
    public void startRun(PrintWriter pW)throws IOException
    {
    while(!finished)
    {
    .
    .
    .
    System.out.println("******");
    pW.println("******");
    pW.flush();
    .
    .
    .
    }
    }


    Any suggestions please. Thanks very much.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    If you have no threads then this looks strange indeed. I would have done the following
    changes:
    The waitToStart method should be invoked by an eventhandler (the buttons
    actionPerformed ?) or invoked at end of GUI initiation, loose the while(!start)
    {} "thing", set finished=false, and finally create & start a normal priority
    thread that perform the while(!finished) -loop. You would probably (?) also
    need a button with an eventhandler that sets finished=true if this flag isn't
    set (safely) within the while(!finished) -loop.
    Last edited by sjalle; 07-26-2005 at 04:24 AM.
    eschew obfuscation

  3. #3
    Join Date
    Jul 2005
    Posts
    28
    Thanks a lot sjalle. It is solved.

    Only to call the waitToStart method in an eventhandler is enough to me so far.

    But why I can not do it the way I did it before?

    Thanks.

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Well, a tight loop like while(!start) {}, when start initially = false,
    doesn't allow much other things to happend, like setting start=true....
    eschew obfuscation

Similar Threads

  1. Order by Rnd Help Needed For Embedded VB???
    By James in forum VB Classic
    Replies: 5
    Last Post: 04-26-2002, 01:42 PM
  2. Strange behavior
    By Paul in forum VB Classic
    Replies: 0
    Last Post: 10-18-2001, 02:10 AM
  3. Can Program run without MS Access
    By Marty in forum VB Classic
    Replies: 2
    Last Post: 04-19-2001, 12:38 AM
  4. How do I run Access Macros or Forms in a VB program?
    By Bruno Baker in forum VB Classic
    Replies: 0
    Last Post: 08-17-2000, 03:35 PM
  5. Program DB Error
    By Leopoldo Rodriguez in forum VB Classic
    Replies: 0
    Last Post: 07-11-2000, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center