I want to implement FIFO (First in First out) approach in Java. The requirement is as following, 1)I receive string data in chunks after some time interval. 2)I want to write it in FIFO buffer having a fixed size i.e. only fixed number of data can be stored(say 5). 3)Then I will pick one by one from the buffer for further processing. 4)After I pick from the buffer it should be deleted from the buffer and the space can be allocated for further data addition. Can anybody guide/ tell me how ti achieve this??? Thnx in advance.
"JavaRanch, where the deer and the Certified play" - David O'Meara
dr priti
Greenhorn
Joined: Mar 05, 2001
Posts: 18
posted
0
Thanx Cindy, but can you elaborate on this. As my understanding of BufferedInputStream is I can take i/p faster. How to achieve FIFO approach with fixed set of values.
karl koch
Ranch Hand
Joined: May 25, 2001
Posts: 388
posted
0
hi, you need an array to put the input to (the size of the array is your fixed size). two indexes: one for the index to write to and one for the index to read from. then you also have to check some conditions: is there space to write, something to read ? use wait() notify()/notifyAll() to prevent deadlocks. the consumer and producer must be different threads in this scenario to prevent deadlocks. perhaps this is a little more than you were looking for but this is FIFO as i understand it........