程序在 Java 中初始化对象输入流时暂停 [英] Program pauses on initializing object input stream in Java

查看:52
本文介绍了程序在 Java 中初始化对象输入流时暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行调试器时,程序暂停从服务器主输入输出流初始化对象流.以下是代码:

While running debugger, the program pauses on initializing object streams from server main input output streams. Following is the code :

 public TFileReader(Client cli)throws Exception{
    this.cli = cli;
    fileSock = new Socket(cli.ServerIp(), cli.FilePort());
    fobjIn = new ObjectInputStream(fileSock.getInputStream());
    fobjOut = new ObjectOutputStream(fileSock.getOutputStream());
    fobjOut.flush();

}

 @Override
public void run(){

    try{
            System.out.println("file reader thread online");

            fobjOut.writeObject(cli.Name());
            fobjOut.flush();
           String per = (String) fobjIn.readObject();
            System.out.println(per+"video filing...");
            if(!per.equals("OKF"))
            {
                    throw new Exception("Error In retriving video.");
            }

它在 fobjIn 上暂停并且不去执行 fobjOut 尽管 fobjIn 它从 fobjIn 断点传递但是不要打断点.

It pauses on fobjIn and do not go to execute fobjOut although fobjIn it passes from fobjIn breakpoint but do not hit out breakpoint.

推荐答案

我会保持这样简单

public TFileReader(Client cli) throws IOException {
    this.cli = cli;
    socket = new Socket(cli.ServerIp(), cli.FilePort());
    out = new ObjectOutputStream(socket.getOutputStream());
    out.flush();
    in = new ObjectInputStream(socket.getInputStream());
}

public void writeObject(Object o) throw IOException {
    out.writeObject(o);
    out.reset();
    out.flush();
}

public <T> T readObject() throw IOException {
    return (T) in.readObject();
}

public void close() throws IOException {
    in.close();
    out.close();
    socket.close();
}

这篇关于程序在 Java 中初始化对象输入流时暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆