我正在使用 dataInputStream 的 readFully 消息来读取固定长度的字节数组:
byte[] record = new byte[4660004];
in.readFully(record);
这里的问题是,有时读取这么多字节需要超过 5 秒,相当于 20000 条记录。我正在套接字上接收这些数据。客户端正在以 4660004 字节的字节数组形式发送数据。有没有办法更快地接收这些数据,因为现在大约需要 5 分钟到 100 万条这样的记录。
编辑:: 完整的数据流:
首先我创建流:
static DataInputStream dIn = null;
dIn = new DataInputStream(connection.getInputStream());
msgType = dIn.readByte();
int msgIntLen = dIn.readInt();
processBatch(msgIntType, msgIntLen, dIn, connector);
.
.
private static void processBatch(int msgIntType, int msgIntLen, DataInputStream in,
Connector connector) throws IOException {
int recordIntLen = in.readInt();
byte[] record = new byte[msgIntLen - 4];
in.readFully(record);
}
如果 wudf 有帮助,我应该在哪里包含缓冲?