Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 68

Thread: Threads!!!

  1. #41
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    Did you find the forever loop and fix it?

    It prints out different results in different runs. There are timing issues with when the threads get executed.
    Last edited by Norm; 11-12-2011 at 10:51 PM.

  2. #42
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Honestly, that was what I thought we were trying to fix with the break; command and the END_PROGRAM we just did? I thought we proved every other one out. If you know that another exists I am happy to try and find it...

  3. #43
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    Does the execution flow from the breaking out of the server loop return to the JVM? Does it exit all the methods that have been called?
    Mine prints these out as it exits:
    S - Client serviced
    S exiting main <<<< THIS is the Server's main method

  4. #44
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    No, mine prints:

    S - End program
    Client serviced
    this.commandLine in ATMRunnable = BALANCE

  5. #45
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    You need to print when the code leaves each method. Do you?
    If you do have printlns at the exit points for the methods, what is keeping the code from executing the printlns?
    What is keeping the code from getting to the printlns and exiting the methods?
    For example:
    Java Code:
    		try 		{
    			Server server = new Server(port);
    			server.serviceClient(server.atmImplementation);
    			System.out.println("S - Client serviced");       //<<<<<<<<<<< HERE
    		} 
    		catch (Exception ex) 		{
    			ex.printStackTrace();
    		}
                   System.out.println("S exiting main");  // <<<<<<<<<<<< HERE
    	} // end main()

  6. #46
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Ok, I put those in, sorry, but I still had to CTRL-C out as you can see...


    S - End program
    S - Client serviced
    S exiting main
    this.commandLine in ATMRunnable = BALANCE
    ^Chuit-smartino:Desktop spm888$

  7. #47
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Norm,

    I need to step away for a couple of hours (family obligation). If you could think of anything else I can be doing to figure this out that would be great, and when I get back I will go at this again...thanks for all your patience!! I want to solve this!!!

    Steve

  8. #48
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    Perhaps you should simplify the testing to see if each of the steps the Client does works.
    For example do only a balance enquiry.
    The do a balance enquiry and a deposit and a balance enquiry.

    How have instances of the Account class is the program supposed to create?

  9. #49
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Note still have to do CTRL-C on the Server with just the BALANCE command only...so something still looping forever???

    I put further down a DEPOSIT and BALANCE 3 times, notice the differing output...

    Balance Only from Client:

    SERVER output:==================

    huit-smartino:Desktop spm888$ java cscie160/hw6/Server 7777
    Accepting clients now
    Client acquired on port #7777, reading from socket
    commandLine from Server equals: BALANCE
    i in the For Loop equals: 0
    o in the For Loop equals: 0
    requestQueueSz in the For Loop equals: 1
    Currently this is the command that is being sent to ATMRunnable: BALANCE
    this.commandLine in ATMRunnable = BALANCE
    S - End program
    S - Client serviced
    S exiting main
    ^Chuit-smartino:Desktop spm888$

    CLIENT output===================

    huit-smartino:Desktop spm888$ java cscie160/hw6/Client localhost 7777
    ATMProxy writing command to server: BALANCE
    Server returned: 0.0
    Balance: 0.0
    ATMProxy: Sending End program

    OUTPUT from CLIENT.java from a DEPOSIT and then BALANCE, 3 different results....

    huit-smartino:Desktop spm888$ java cscie160/hw6/Client localhost 7777
    Depositing: 1000
    ATMProxy writing command to server: DEPOSIT
    ATMProxy writing command to server: BALANCE
    Server returned: 0.0
    Balance: 0.0
    ATMProxy: Sending End program

    ================================================== ==

    huit-smartino:Desktop spm888$ java cscie160/hw6/Client localhost 7777
    Depositing: 1000
    ATMProxy writing command to server: DEPOSIT
    ATMProxy writing command to server: BALANCE
    Server returned: 21000.0
    Balance: 21000.0
    ATMProxy: Sending End program

    ================================================== ===

    huit-smartino:Desktop spm888$ java cscie160/hw6/Client localhost 7777
    Depositing: 1000
    ATMProxy writing command to server: DEPOSIT
    ATMProxy writing command to server: BALANCE
    Server returned: 55000.0
    Balance: 55000.0
    ATMProxy: Sending End program

    ================================================== ====

    Quote Originally Posted by smartino View Post
    Couple of questions:

    Did the locations that I put your supplied code make sense, i.e.: that is where they should have gone?

    The output you just sent was from the Server.java side, do you get the same on the Client.java side for output?

    Do you need to CTRL-C out of the Server.java program to force it to end?

    thanks again,

  10. #50
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    How have instances of the Account class is the program supposed to create?

    so something still looping forever???
    Do you have a resource manager that will tell you if your program is executing, using CPU cycles? On Windows you can see if the program is using CPU cycles or not.
    If not using cycles then it is probably blocked waiting for some event or data.

  11. #51
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Definitely looping or waiting for something since that is why the balance is so high since it keeps depositing 1000 as fast as my Mac can do it!!!

    I know it is eating up CPU cycles, since my Mac (not kidding) will begin to heat up, I have a monitor on the temperature of the device and it quickly starts incrementing in degrees....if I don't kill the Server.java program!!!

    I just ran the Monitor on my program, I think it is attached, but either way, the CPU spiked to 100% and continued that way until I killed Server.java. It then dropped immediately to nothing.

    Do you think this is s loop or a threading issue??

    More output from Client showing differing results each run...

    huit-smartino:Desktop spm888$ java cscie160/hw6/Client localhost 7777
    ATMProxy writing command to server: DEPOSIT
    ATMProxy writing command to server: BALANCE
    Server returned: 293000.0
    Balance: 293000.0
    Withdrawing: 250
    ATMProxy writing command to server: BALANCE
    Server returned: 322000.0
    Balance: 322000.0
    Withdrawing: 750
    ATMProxy writing command to server: WITHDRAW
    ATMProxy writing command to server: BALANCE
    Server returned: 325000.0
    Balance: 325000.0
    ATMProxy: Sending End program

    Threads!!!-monitor.jpg

  12. #52
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    Find the loop.
    Add a println inside of every loop in the program.

    How many instances of the Account class is the program supposed to create?

  13. #53
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Are you sure it is a loop and not a thread issue that is waiting on another thread to release a variable, method, etc. LOOK at me questioning you!!! I don't mean to, but I just want to be sure I am looking for the right thing. I will got off and start finding my loops...unless you say otherwise...

  14. #54
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Here is the code that never ends in ATMRunnable.java, the System.out.println("I am in ATMRunnable in a while loop"); just keeps going and going and going...no end...I am sure it is not getting a null....


    public synchronized void run()
    {
    System.out.println("this.commandLine in ATMRunnable = " + this.commandLine);
    PrintStream printStream = new PrintStream(outputStream);

    while (this.commandLine != null)
    {
    System.out.println("I am in ATMRunnable in a while loop");
    try
    {
    Float result = executeCommand(this.commandLine);
    // Only BALANCE command returns non-null
    if (result != null)
    {
    printStream.println(result); // Write it back to the client
    }
    }
    catch (ATMException atmex)
    {
    System.out.println("ERROR: " + atmex);
    }

    }
    System.out.println("I now out of the ATMRunnable while loop");
    }

  15. #55
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    Java Code:
    while (this.commandLine != null)
    How is the loop supposed to end? When does commandLine change? What code is supposed to change it?

    And you have not answered this question yet:
    How many instances of the Account class is the program supposed to create?

  16. #56
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Lets see if I can answer your questions:

    The loop is supposed to end when the value of commandLine sends a null value, The issue is I am not getting a null value....

    The commandLine changes every time I send a new command from Client.java. The code in Client.java....

    I believe I should only be creating 1 instance of the Account class.

    (I actually thought to put in the code you wrote before in ATMImplementation.java, and did, but still no luck)...


    if(this.commandLine.indexOf(Commands.END_PROGRAM.t oString()) >= 0) {
    System.out.println("S - End program");
    break; // done
    }

  17. #57
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    The commandLine changes every time I send a new command from Client.java.
    But how does is change while the loop is executing?

    I believe I should only be creating 1 instance of the Account class.
    Another place to put a println to see what is happening. You really need to add many printlns to see what your code is doing.


    I'm done for tonight.

  18. #58
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    Thanks Norm for sticking in there all day...

    Another fun fact is if I start with anything beside "BALANCE" as my first command I get balances other than 0 back, whenever I start with BALANCE, it never give me BALANCES other than 0...

    I will try to investigate more, thanks again...have a good night...

  19. #59
    smartino is offline Member
    Join Date
    Sep 2011
    Posts
    64
    Rep Power
    0

    Default Re: Threads!!!

    I have been messing around with synchronizations all morning, but to no avail, same behavior, are we ready for another day of trying to track this issue down?

    Best thoughts on where I should go now?

  20. #60
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Threads!!!

    I think you have all the tools for finding your problem: printlns and more printlns that show where the code is executing and how the values of variables are changing.
    Do one thing at a time and figure out why it is not working. Fix it and then add one more thing to the test, figure it out, fix it, and so on and so on.

    Good luck.

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Threads
    By nsr2008.mca in forum New To Java
    Replies: 7
    Last Post: 10-18-2010, 11:47 AM
  2. Threads and UML
    By JUser in forum Advanced Java
    Replies: 0
    Last Post: 09-27-2010, 08:43 PM
  3. Threads
    By Tanuck in forum New To Java
    Replies: 5
    Last Post: 09-21-2010, 02:44 AM
  4. When to use threads
    By simorgh in forum Threads and Synchronization
    Replies: 2
    Last Post: 02-12-2010, 07:43 AM
  5. Threads
    By one198 in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 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
  •