Results 1 to 5 of 5
  1. #1
    JDaniel is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default Breaking the thread.

    Hello i have following situation in my program. I create a thread which is responsible for reading the data from server.


    Java Code:
    while (clientapp.connected == true) {
                    try {
                        indata = (NetworkData) in.readObject();
                    } catch (Exception e) {
                         ;
                    }
    
                }
    The problem comes when I want to close the application (eg. by pressing the button), I use it in normal way by calling some method which changes clientapp.connected value to false. However the loop won't proceed because it's stuck in readObject() which is blocking method. So until the server sends me something I can't close this thread. Do you have any idea how to solve this issue?

  2. #2
    JDaniel is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    Ok, sorry for that - solved. I just break the "in" stream with a method, so the readObject() throws an exceprion and im out.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JDaniel View Post
    Java Code:
                    } catch (Exception e) {
                         ;
                    }
    Seriously? You're completely ignoring the exception? This begs the question -- why?

  4. #4
    JDaniel is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    No, Im not. I wrote only the loop template, there was too much code in the exception braces to print it here.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JDaniel View Post
    No, Im not. I wrote only the loop template, there was too much code in the exception braces to print it here.
    Phew! Thanks for clarifying that. :)

Similar Threads

  1. breaking up
    By smray7 in forum New To Java
    Replies: 2
    Last Post: 10-31-2010, 08:58 AM
  2. breaking out of while loop
    By mac in forum New To Java
    Replies: 5
    Last Post: 05-18-2010, 04:21 PM
  3. Breaking up of array
    By agarwal_srushti in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 08:03 PM
  4. Breaking for-loops with listeners?
    By CBarry in forum New To Java
    Replies: 3
    Last Post: 04-22-2009, 04:38 AM
  5. Breaking down an integer
    By Emily in forum New To Java
    Replies: 1
    Last Post: 03-06-2008, 07:39 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
  •