1

I have developed a midlet that uses an HttpConnection. There is a separate thread that does the connection.

Now what I did was provide another method called cancel() on that Thread which will call HttpConnection.close() even when HttpConnection is being used in the run() method.

This way I sort of interrup/cancel the connection. This works fine on my sun wireless emulator but it does not work on Nokia device and Nokia SDK2.

Is it possible that one thread is using the HttpConnection and another thread is calling close() on it? I was expecting an Exception to be thrown but instead the midlet hangs.

zx81
  • 41,100
  • 9
  • 89
  • 105
Tanaji
  • 53
  • 2
  • 1
    You need to strip your MIDlet down to the smallest amount of code necessary to reproduce the error. That will probably help you fix it. If it still persists, post the code here and somebody can help. – funkybro Aug 31 '12 at 13:38
  • I using async call for Http Request using [Ajax-like Asynchronous SOA Calls with Java ME.](http://developers.sun.com/mobility/midp/ttips/soacalls/) and after request make. request wait for ResponceCode. That time i try to close connection from MIDlet connection not close immediately. – Tanaji Aug 31 '12 at 14:13
  • 1
    upload your code please. – Lucifer Sep 01 '12 at 05:15

1 Answers1

0

When doing IO you need to be aware that most methods can be blocking unless otherwise stated in the documentation. HTTPConnection.close() is one such method.

My guess (since you haven't shared any code) is that you call close() from the main GUI thread and thus hang the MIDlet when the method blocks. The best way would probably be to instead set an "aborted" boolean in the thread doing the connection and check it in strategic places. As an alternative you can spawn of a "close thread" that does the possibly blocking close call.