【问题标题】:How to interrupt a waiting input of java [duplicate]如何中断java的等待输入[重复]
【发布时间】:2013-06-20 13:12:52
【问题描述】:
MainActivity.this.in = MainActivity.this.uart.getInputStream();
int re = in.read();

以上所有内容都是我的部分代码。我想从外围设备中读取一个数字。如果等待时间超过 3 秒。停止!然后出现警告信息!但我不知道如何中断等待。

【问题讨论】:

    标签: java wait interrupt


    【解决方案1】:

    在调用in.read();之前尝试将so_timeout设置为Socket.setSoTimeout(3000L)等相应的套接字

    【讨论】:

    • 感谢您的回答!但我不是在做网络编程。
    • 光标 cursor = DBHelper.getInstance(MainActivity.this).select(); ArrayList all = new ArrayList(); while (true) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor .moveToNext()) { all.add(cursor.getInt(0)); } 标签: for (int sstr : all) { final int forWarningInfo = sstr;尝试 { out.write(hexStringToBytes(sendOrder[sstr - 1])); } catch (IOException e) { e.printStackTrace(); }
    猜你喜欢
    • 1970-01-01
    • 2016-11-16
    • 2014-06-20
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多