私は現在、私のカレッジクラスのネットワーク割り当てを書いていますが、少し問題があります。この割り当ては、あらかじめ定義されたメッセージセットを使用してソケット上で互いに通信するノードのセットを設定することから成ります。これらのメッセージは、ソケットの4番目と4番目に送信されるバイトデータから構築できなければなりません。ここネットワーキング宿題のJava.lang.OutOfMemoryError
[]はバイトからのデータを処理するメッセージのいずれかの内部の方法の例である:
public void processData(byte [] data) throws IOException
{
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(data));
//get the status code
statusCode = (byte)stream.read();
System.out.println("Status Code: "+statusCode);
//get the additional info
byte [] additionalInfoData = new byte[stream.readInt()];
stream.read(additionalInfoData, 0, additionalInfoData.length);
additionalInfo = new String(additionalInfoData);
System.out.println("additionalInfo: "+statusCode);
stream.close();
}
Iは、プログラムを実行し、それがこの点に到達すると(これは最初の後のメッセージ)が送られてきた、それはこの例外に
byte [] additionalInfoData = new byte[stream.readInt()];
に一時的に停止させます。
Exception in thread "Thread-1" java.lang.OutOfMemoryError: Java heap space at cdn.wireformats.RegisterResponse.processData(RegisterResponse.java:58) at cdn.wireformats.RegisterResponse.<init>(RegisterResponse.java:31) at cdn.wireformats.WireFormatFactory.getWireFormatMessage(WireFormatFactory.java:22) at cdn.communications.Link.readMessage(Link.java:62) at cdn.communications.Link.run(Link.java:98) at java.lang.Thread.run(Thread.java:679)
この問題を解決する方法はありますか?バイト[]からデータを間違って読み込んでいますか?
ストリームの大きさ、つまり「stream.readInt()」は何を返しますか?どのくらいのメモリをJVMに与えますか?最大メモリを設定するか、デフォルトのままにしますか?どのJVM - ホットスポット、JRockit、...? – Thomas