从流中读取时如何调用/执行超时

问题描述

从流中读取时如何调用/执行超时?我在log4j附加程序的jdbc中测试dbcp2池,并且需要在单元测试中检查民意测验是否有效。我尝试设置sleep(5000),但不起作用-超时未显示

final InputStream from_client = client.getInputStream();
final OutputStream to_server = server.getoutputStream();

new Thread() {
    public void run() {
        int bytes_read;
        try {
            while((bytes_read = from_client.read(request)) != -1) {

                if (interrupt) {
                    System.out.println("I trying to invoke timeout .... " + interrupt);
                    Thread.sleep(5000);
                    interrupt = false;
                }
                
                to_server.write(request,bytes_read);
                to_server.flush();
            }
        }
        catch (IOException e) {}
        
        try {
            to_server.close();
        } catch (IOException e) {}
    }
}.start();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)