|
ObjectFIFO Demo - Instructions
Overview
First-In-First-Out (FIFO) queues allow items to be added to one end of the queue and removed from the other end.
Items are removed in the exact same order as they were added (the first item in is the first item out).
A FIFO queue has a fixed capacity. If a thread invokes the add(Object obj) method when the FIFO is full, it blocks waiting
until another thread removes an item (If the add(Object obj, long msTimeout) method is called, it
will return if the specified timeout is reached prior to another thread removing an item). If a thread invokes
the remove() method when the FIFO is empty, it blocks until another thread adds an item (If the
remove(long msTimeout) method is called, it will return if the specified timeout is reached prior to
another thread adding an item).
ObjectFIFO is a FIFO queue that
allows you to store Objects of any non-primitive type. JThreadkit has other FIFO queues that support
primitive types like byte or int. In the ObjectFIFODemo, we are storing
Strings in the ObjectFIFO.
Running the Demo
Once the demo has been launched, the following steps can be taken to observe the ObjectFIFO's behavior:
Adding Items
-
Type a
String into the "Add Entry" text field. To add the String without a timeout (potentially waiting forever
if the queue is full), click the "Add" button, or simply press "Enter". You now see the String added to the
queue (represented by the grid in the center of the window).
-
To add a
String with a timeout, check the "Timeout After" radio button and enter
a timeout value (in milliseconds) in the timeout text field. Then enter a String and click "Add". If
the queue is not full, the String will be added immediately. If the queue is full
and no items are removed from the queue during the timeout period, the add will timeout. The information related
to how long it takes for the timeout will be displayed in the text area below the "Add Entry" box.
-
All results related to adding are displayed in the text area below the "Add Entry" box.
Removing Items
-
To remove a
String without a timeout (potentially waiting forever if the queue is empty), simply click
the "Remove One" button in the "Remove Entry(ies) " box. If a String is removed, notice that it was the
first String that was added, and the ObjectFIFO's size is adjusted accordingly.
-
To remove multiple
Strings, enter a minimum and a maximum number to be removed in the text fields and then click the
"Remove" button.
-
To remove a
String with a timeout, check the "Timeout After" radio
button and enter a timeout value (in milliseconds) in the timeout text field. Then click "Remove One". If there
are items in the queue, the remove will happen immediately. If the queue is empty, and no items are added to the
queue during the timeout period, the remove will timeout. The information related to how long it takes for the
timeout will be displayed in the text area below the "Remove Entry(ies)" box.
-
All results related to removing are displayed in the text area below the "Remove Entry(ies)" box.
Changing Capacity
-
To change the capacity of the queue, enter a new value in the capacity text field and click "Change". The grid will
now display the same number of "slots" as the new capacity, unless the new capacity is less than the current
size. In this case, the capacity is silently increased to match the current size.
|