Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User cstommijx's Avatar
    Join Date
    Jun 2006
    Posts
    21
    im havin an issue with Thread, Im using a seperte thread to connect to the network and so, i am using a while-loop to stop the execution of the codes further down. but things seems to get stuck in the while-loop

    private boolean blnDone = false;

    ReadWeb readWeb = new ReadWeb();
    Thread tRW = new Thread(readWeb);
    tRW.start();

    while (blnDone == false) {

    try {
    Thread.sleep(1000);

    } catch (Exception e) {
    }
    //LOOP IS NEVER EXIT
    }

    /*
    *codes to execute after data is retreived from jsp through the thread, but it never comes down.
    */


    class ReadWeb implements Runnable {

    String strResult = ""; //testing

    public void run() {
    StreamConnection stc = null;
    InputStream is = null;
    StringBuffer b = new StringBuffer();

    try {
    stc = (StreamConnection) Connector.open("http://www.yahoo.com");
    is = stc.openInputStream();
    int ch;

    while ((ch = is.read()) != -1) {
    b.append((char)ch);
    }

    System.out.println(b.toString());

    } catch (Exception e) {
    e.printStackTrace();
    } finally {

    if (is != null) {
    try {
    is.close();
    } catch (Exception e) {}
    }

    if (stc != null) {
    try {
    stc.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    }
    blnDone = true;
    }

    }

  2. #2
    Super Contributor peterblazejewicz's Avatar
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,699
    hi,

    make sure that:
    - you are using the same "blnMade" field - some IDE's could create variable fields for you, so you can have two different blnMade (with different visiblity),
    - comment yoru "while" loop in runnable to check if that is not stuck on that loop (just in case)
    or comment entire code in runnable start() to let thread to return immadiately,
    Your code is working fine for me (in Sun WTK emulator),

    regards,
    Peter

Similar Threads

  1. console app running problem
    By xcompass in forum Symbian C++
    Replies: 3
    Last Post: 2009-05-08, 13:26
  2. Does an EXE called from APP run in a seperate thread?
    By ViruDoshi in forum Symbian C++
    Replies: 10
    Last Post: 2006-02-28, 13:05
  3. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46
  4. RunL() method is not being called
    By dotcdotc in forum Symbian C++
    Replies: 9
    Last Post: 2004-12-13, 11:25
  5. visual c++ stuck in infinite loop (SDK)
    By deloford in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-03-06, 09:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved