File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes FIFO implementation in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "FIFO implementation in Java" Watch "FIFO implementation in Java" New topic
Author

FIFO implementation in Java

dr priti
Greenhorn

Joined: Mar 05, 2001
Posts: 18
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.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Sounds like what a BufferedInputStream does.
BufferedInputStream in = new BufferedInputStream( new FileInputStream(FileName));


"JavaRanch, where the deer and the Certified play" - David O'Meara
dr priti
Greenhorn

Joined: Mar 05, 2001
Posts: 18
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
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........

karl
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FIFO implementation in Java
 
Similar Threads
How does Apache Tomcat server handle the HTTPrequests?
Broken Messages in a socket buffer
Difference between PushbackInputStream and BufferedInputStream?
jsp:forward problem