未捕获的异常:BlackBerry上的事件分派线程不允许阻止操作

时间:2010-11-25 08:40:37

标签: multithreading blackberry java-me thread-safety

我有一个HttpConnection线程类。当ı停止httpConnection时,我会显示这个消息。 怎么应该停止httpConnection ??

Blackberry输出控制台:

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

My Connection类的一部分:

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

我的屏幕课程的一部分:

public void close() {
        super.close();
        StaticVar.ActiveCam.cancel();
//      CameraListScreen screen = new CameraListScreen();
//      UiApplication.getUiApplication().pushScreen(screen);
//
    }

部分Camera Class / * ActiveCam的取消在这里 /:

// finishes connection.
    public void cancel() {
        setConnected(false);
        if (mjpeghttp != null) {
            mjpeghttp.cancel();
            //mjpeghttp.interrupt();
            //mjpeghttp = null;

        }
            }

2 个答案:

答案 0 :(得分:1)

看起来您的HttpConnection是从后台(非UI)线程访问的,这很好。但是你的UI直接调用close()可能会阻塞。你应该考虑产生另一个线程来做close()。

答案 1 :(得分:0)

您必须仅使用事件线程中的屏幕

 //safely (recommended)
 Application.getApplication().invokeLater(new Runnable() {
        public void run() {
            //your code here
         }
 });

//fast 
synchronized(Application.getEventLock()) {
   //your code here
 }