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;
}
}

Reply With Quote

