Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
SynchroList. In this column I'll update that class so that I can subset the collection. Then we'll go through the issues that arise when
multiple threads use a subsetted collection. Finally, I'll show you an applet I wrote that helps demonstrate what is going
on inside the collection when multiple threads are accessing it.The class that I created in part 1 of this series is called a SynchroList, and it is an ordered collection. Being ordered means that the objects within the collection have some notion of order associated with them. For
example, words may be sorted into alphabetical order, numbers into numerical order, and so on. In the case of my class, the
ordering is determined by a helper class called a Comparator. This ordering is similar to the way in which collections are set up in the 1.2 release of Java.
Once a collection is ordered, a user of the collection can specify a subset of elements in terms of example objects. While this may be confusing at first, it turns out to be a pretty simple concept.
Consider a collection of words (which for the purpose of this example will consist of an arbitrary number of characters and letters, tokens, not necessarily English words) that are ordered alphabetically using the convention that letters that appear earlier in the alphabet are considered to have a value less than letters that appear later in the alphabet. Within the collection, you may wish to select all tokens that start with the letter a. You make your selections from the list by comparing all of the tokens in the list with the tokens "a" and "b." If the list element is greater than or equal to the first token, that element is included in the subset as long as it is also less than the second token. The tokens selected become the subset. That subset can be expressed as ("a," "b"]. The difference between the ( symbol and the ] symbol is that a parenthesis implies greater than or equal to, while the bracket implies less than. The set is said to be inclusive of "a" and exclusive of "b."
To implement subsets in the SynchroList class I changed the inner class LinkEnumerator. Why? The original LinkEnumerator (for a review, see the original source in part 1 of this series) had only the null constructor. This set an internal index variable named current to point to the head of the sorted list of Link objects. In the new version of this class we add two constructors for returning subsets of the list. Further, we've added
a pointer to the last object to be returned, named last, that tells the class when it has reached the end of the list. The original constructor was modified as follows:
LinkEnumerator( ) { current = head; last = null }
Next we've added two additional constructors to return subsets of the list. The first returns the subset from and object referenced by the variable from to the end of the collection. This constructor is shown next: