avinash.lakshman at gmail.com
Thu Sep 2 11:23:27 PDT 2010
Should I assume similar semantics with the UDP too? I/O is not completed in
a single operation even in UDP.
On Thu, Aug 19, 2010 at 1:19 AM, Alan Bateman <Alan.Bateman at oracle.com>wrote:
> Avinash Lakshman wrote:
>> Hi All
>> I want to use the write() on the AsynchronousSocketChannel which has no
>> timeout semantics. I also want to pool these connections that I use. Now if
>> I have multiple threads writing into the same connection, even though the
>> writes are synchronized, I get a WritePendingException because a previous
>> write has not completed. What is the general paradigm for handling this? Do
>> I need to keep track of pending writes etc?
> I wonder if this is the right API for what you are doing. If you've got
> multiple threads wanting to write to the same stream then the writing will
> need to be coordinated to avoid "corrupting" the stream. A write to a
> channel is not guaranteed to write all the remaining bytes in the buffer and
> so the buffer prepared by one of the threads may actually require several
> I/O operations. The only thing I can suggest is that you maintain a queue of
> buffers to be written, and use the the completion notification to initiate
> the next write operation (which might be from the same buffer, or the next
> buffer in the queue). I think there are other folks on this mailing list
> that have been through this before and they might be able to advise or
> provide samples from their own usage.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nio-discuss