Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I second <a href="https://stackoverflow.com/questions/207829/best-approach-to-use-in-java-6-for-a-list-being-accessed-concurrently#208009">Telcontar's suggestion</a> of a database, since they are actually designed for managing this scale of data and negotiating between threads, while in-memory collections are not.</p> <p>You say that the data is on a database on the server, and the local list on the clients is for the sake of user interface. You shouldn't need to keep all 100000 items on the client at once, or perform such complicated edits on it. It seems to me that what you want on the client is a lightweight cache onto the database.</p> <p>Write a cache that stores only the current subset of data on the client at once. This client cache does not perform complex multithreaded edits on its own data; instead it feeds all edits through to the server, and listens for updates. When data changes on the server, the client simply forgets and old data and loads it again. Only one designated thread is allowed to read or write the collection itself. This way the client simply mirrors the edits happening on the server, rather than needing complicated edits itself.</p> <p>Yes, this is quite a complicated solution. The components of it are: </p> <ul> <li>A protocol for loading a range of the data, say items 478712 to 478901, rather than the whole thing</li> <li>A protocol for receiving updates about changed data</li> <li>A cache class that stores items by their known index on the server</li> <li>A thread belonging to that cache which communicated with the server. This is the only thread that writes to the collection itself</li> <li>A thread belonging to that cache which processes callbacks when data is retrieved</li> <li>An interface that UI components implement to allow them to recieve data when it has been loaded</li> </ul> <p>At first stab, the bones of this cache might look something like this:</p> <pre><code>class ServerCacheViewThingy { private static final int ACCEPTABLE_SIZE = 500; private int viewStart, viewLength; final Map&lt;Integer, Record&gt; items = new HashMap&lt;Integer, Record&gt;(1000); final ConcurrentLinkedQueue&lt;Callback&gt; callbackQueue = new ConcurrentLinkedQueue&lt;Callback&gt;(); public void getRecords (int start, int length, ViewReciever reciever) { // remember the current view, to prevent records within // this view from being accidentally pruned. viewStart = start; viewLenght = length; // if the selected area is not already loaded, send a request // to load that area if (!rangeLoaded(start, length)) addLoadRequest(start, length); // add the reciever to the queue, so it will be processed // when the data has arrived if (reciever != null) callbackQueue.add(new Callback(start, length, reciever)); } class Callback { int start; int length; ViewReciever reciever; ... } class EditorThread extends Thread { private void prune () { if (items.size() &lt;= ACCEPTABLE_SIZE) return; for (Map.Entry&lt;Integer, Record&gt; entry : items.entrySet()) { int position = entry.key(); // if the position is outside the current view, // remove that item from the cache ... } } private void markDirty (int from) { ... } .... } class CallbackThread extends Thread { public void notifyCallback (Callback callback); private void processCallback (Callback) { readRecords } } } interface ViewReciever { void recieveData (int viewStart, Record[] records); void recieveTimeout (); } </code></pre> <p>There's a lot of detail you'll have to fill in for yourself, obviously.</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.
    1. VO
      singulars
      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