简体   繁体   English

允许推回的java fifo队列?

[英]java fifo queue that allows pushing back?

is there a fifo queue implementation that provides for replacing the head element after a peek? 是否有一个fifo队列实现,提供在偷看后替换head元素?

i'd like to use this to push a partially written buffer back onto the queue after a partial write onto a network connection (when using java nio selector). 在部分写入网络连接(使用java nio选择器)后,我想使用它将部分写入的缓冲区推回队列。

this would be a bit cleaner than sticking the partially written buffer as an attachment on the selection key, but if there's no convenient implementation available I'll have to use that. 这将比将部分写入的缓冲区作为选择键上的附件更清晰,但如果没有方便的实现可用,我将不得不使用它。

You can use a Deque which allows you to add to the start or the end. 您可以使用Deque ,它允许您添加到开头或结尾。

However, if you have a partial write and your buffers are not huge, you could have a slow consumer and you might consider a different action such as closing the connection. 但是,如果您有部分写入并且缓冲区不是很大,那么您可能会有一个缓慢的消费者,您可能会考虑采取其他操作,例如关闭连接。

After a peek the head element is undisturbed, so your question doesn't make sense. 偷看后,头部元素不受干扰,所以你的问题没有意义。 Just peek, try the write, and if there is nothing left then remove the buffer from the queue. 只是偷看,尝试写,如果有精光,然后从队列中删除的缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM