I have a HttpConnection thread class. when ı stop httpConnection, I show this messeage. how should ı stop httpConnection??
Blackberry Output Console:
RuntimeException
blocking operation not permitted on event dispatch thread
net_rim_cldc-10
EventThreadCheck
throwException
0x3434
net_rim_cldc_io_tcp
Protocol
<private>
0x18B8
net_rim_cldc_io_tcp
Protocol
outputStreamClosed
0xB2D
net_rim_cldc_io_tcp
TcpOutputStream
close
0x40BF
net_rim_os-2
ClientProtocol
close
0x154E
CepVizyon-2
Http
cancel
0x174F
CepVizyon-2
Camera
cancel
0x6E7
CepVizyon
ViewCam
close
0xE79
net_rim_cldc-7
Screen
onClose
0x5DAC
net_rim_cldc-7
Screen
keyCharUnhandled
0x5C58
net_rim_cldc-9
MainScreen
keyCharUnhandled
0x23D7
net_rim_cldc-7
Screen
dispatchKeyEvent
0x51DB
net_rim_cldc-7
Screen
processKeyEvent
0x718D
net_rim_cldc-7
UiEngineImpl
processMessage
0x9E3C
net_rim_cldc-4
Application
processNextMessage
0x1073
net_rim_cldc-4
Application
enterEventDispatcher
0x775
CepVizyon-2
CepVizyonMain
main
0x1175
parts of My Connection class:
public abstract class Http extends Thread{
protected HttpConnection httpConnection;
HttpConnectionFactory factory;
protected static Base64 base64;
private boolean cancel = false;
/** bağlantının yapılcağı adres */
protected String url = "";
/** paremetre olarak gönderilecek data */
protected String queryString = "";
...
public void cancel() {
try {
if (httpConnection != null)
httpConnection.close();
if(factory!=null)
factory.cancel();
} catch (IOException ex) {
}
cancel = true;
}
part of my screen class:
public void close() {
super.close();
Static开发者_StackOverflow社区Var.ActiveCam.cancel();
// CameraListScreen screen = new CameraListScreen();
// UiApplication.getUiApplication().pushScreen(screen);
//
}
and part of Camera Class/*ActiveCam's cancel is here/:
// finishes connection.
public void cancel() {
setConnected(false);
if (mjpeghttp != null) {
mjpeghttp.cancel();
//mjpeghttp.interrupt();
//mjpeghttp = null;
}
}
It looks like your HttpConnection is accessed from a background (non UI) thread which is good. However your UI calls close() directly which may block. You should consider spawning another thread to do the close().
You must work with screen only from event thread
//safely (recommended)
Application.getApplication().invokeLater(new Runnable() {
public void run() {
//your code here
}
});
or
//fast
synchronized(Application.getEventLock()) {
//your code here
}
精彩评论