0

と がObjectOutputStreamありObjectInputStreamます。それらを介してintとオブジェクトを送信しようとします。今、私は何とか送信してポイントまで読むことができましたが、なぜそこで止まるのかわかりません。

ポイントは次のとおりです。

読者:

    while (true) {
        start = in.readInt();
        System.out.println("PART 1");
        int temp1 = in.readInt();
        int temp2 = in.readInt();
        int temp3 = in.readInt();
        System.out.println("PART12");
        Chunk temp = new Chunk(temp1,temp2, temp3);
        while (true) {

part12 に到達しない (最初の int を渡さない...)

ライター:

 if (chunkList != null) {
        for (Chunk c: chunkList) {
            out.writeInt(-1);
            out.writeInt(c.getLocation().getX());
            out.writeInt(c.getLocation().getY());
            out.writeInt(c.getLocation().getZ());
            if (c.getTileList() != null) {

すべてを正常に渡します。

私は別のスレッドで 2ms ごとに out.flushing しています。

スレッド:

 while (true)
        {
            while (c.sendPacket()) {

            try
            {
                if (c.getOut() != null)
                {
                    c.getOut().flush();
                }
            }
            catch (IOException ioexception)
            {
                ioexception.printStackTrace();
            }

            try
            {
                sleep(2L);
            }
            catch (InterruptedException interruptedexception) { }
            }
        }

3 ints の部分で読み取りが停止するのはなぜですか?

4

1 に答える 1

0

これはスレッドセーフの問題だと思います。原則として、ストリームはスレッドセーフになるようには設計されていません。したがって、2つのスレッドをより高いレベルで同期していない限り、1つのスレッドがストリームに書き込み、2番目のスレッドがflushを呼び出すことは安全ではありません。

于 2012-05-26T01:54:34.777 に答える