Stopping a Thread blocking on I/O
Hi,
Does anyone have a simple, elegant and clean solution for stopping a Thread that is blocking on an I/O call in an MIDP client.
My problem is that any of the Java I/O calls could block while sending a request or receiving a response but the user must have the ability to Stop his current request at any time.
Any help please.
Many Thanks,
Vinesh.
My code is as follows :
public class MessageHandler extends Thread
{
private static Communication comms = null;
........
........
public void run()
{
try
{
........
........
// Do Some Processing of the Input data here
........
........
// Send Request / Receive Response
byte bOut[] = null;
bOut = comms.DoServerCall(bInData);
........
........
// Do Some Processing of the Output data here
........
........
}
........
........
}
}
public class Communication
{
private String url;
........
........
public Communication(String url)
{
this.url = url;
}
public byte [] DoServerCall(byte request[]) throws IOException
{
HttpConnection conn = null;
InputStream in = null;
OutputStream out = null;
byte response[] = null;
// Open Connection
conn = (HttpConnection)Connector.open(url);
........
........
// Send Request
out = conn.openOutputStream();
out.write(request);
out.flush();
// Receive Response
int rc = conn.getResponseCode();
........
........
in = conn.openInputStream();
int lengthResponse = (int) conn.getLength();
........
........
response = IOUtil.BufferedByteRead(in, lengthResponse, url);
// BufferedByteRead method just reads the entire response in a while loop
// while (remaining > 0)
// {
//int bytesRead = in.read(bReceived, offset, remaining);
//........
//........
// }
........
........
return response;
}
}

