0

我的班级里面有一个run-method扩展Thread的 . 代码片段:

    public void run() {
        Log.i(TAG, "BEGIN mConnectedThread");
        byte[] buffer = new byte[1024];
        int bytes;

        Log.i("INSIDE RUN: ", "STARTING LISTNING FOR INPUTSTREAM" ); 
        // Keep listening to the InputStream while connected

        while (true) {
            try {
                // Read from the InputStream
                bytes = mmInStream.read(buffer);

                //Log.d("BYTES FROM THE DEVICE: ", Integer.toString(bytes));

            } catch (IOException e) {
                Log.e(TAG, "disconnected", e);

                break;
            }
        }
    }

一段时间后,LogCat 给了我以下错误:

07-27 14:51:55.860: E/dalvikvm(17271): threadid=2: stuck on threadid=1187, giving up

我认为这条错误消息试图告诉我的是线程正在 aspinlock和 doBusy waiting中,就操作系统相关的东西而言。但是为什么要忙等待,我实际上正在做一些事情,阅读流。谁能指出我正确的方向?谢谢!

4

0 回答 0