Note that there are some explanatory texts on larger screens.

plurals
  1. POAsking about threading, arrays and cache memory
    primarykey
    data
    text
    <p>I hope in a good manner :-) I wrote this piece of code. What I wished to do, is to build something like "cache". I assumed that I had to watch for different threads, as might many calls get to that class, so I tried the ThreadLocal functionality. Base pattern is have "MANY SETS of VECTOR" The vector holds something like: VECTOR.FieldName = "X" VECTOR.FieldValue= "Y" So many Vector objects in a set. Different set for different calls from different machines, users, objects.</p> <pre><code> private static CacheVector instance = null; private static SortedSet&lt;SplittingVector&gt; s = null; private static TreeSet&lt;SplittingVector&gt; t = null; private static ThreadLocal&lt;SortedSet&lt;SplittingVector&gt;&gt; setOfVectors = new ThreadLocal&lt;SortedSet&lt;SplittingVector&gt;&gt;(); private static class MyComparator implements Comparator&lt;SplittingVector&gt; { public int compare(SplittingVector a, SplittingVector b) { return 1; } // No need to override equals. } private CacheVector() { } public static SortedSet&lt;SplittingVector&gt; getInstance(SplittingVector vector) { if (instance == null) { instance = new CacheVector(); //TreeSet&lt;SplittingVector&gt; t = new TreeSet&lt;SplittingVector&gt;(new MyComparator()); t.add(vector); s = Collections.synchronizedSortedSet(t);//Sort the set of vectors CacheVector.assign(s); } else { //TreeSet&lt;SplittingVector&gt; t = new TreeSet&lt;SplittingVector&gt;(); t.add(vector); s = Collections.synchronizedSortedSet(t);//Sort the set of vectors CacheVector.assign(s); } return CacheVector.setOfVectors.get(); } public SortedSet&lt;SplittingVector&gt; retrieve() throws Exception { SortedSet&lt;SplittingVector&gt; set = setOfVectors.get(); if (set == null) { throw new Exception("SET IS EMPTY"); } return set; } private static void assign(SortedSet&lt;SplittingVector&gt; nSet) { CacheVector.setOfVectors.set(nSet); } </code></pre> <p>So... I have it in the attach and I use it like this:</p> <pre><code>CachedVector cache = CachedVector.getInstance(bufferedline); </code></pre> <p>The nice part: Bufferedline is a splitted line based on some delimiter from data files. Files can be of any size.</p> <p>So how do you see this code? Should I be worry ? I apologise for the size of this message!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload