Not violating "compareTo" contract in a changing list
<p>This is kind of a general java question and doesn't relate too much to Android.</p>

<p>In my application I have a list of some objects of a medium complex class which implements <code>Comparable</code>. The <code>compareTo()</code> method's result depends on some of the fields. The method is consistent and doesn't violate the comparison contract, when the elements aren't modified during the comparison.</p>

<p>Now to the problem. The list must be sorted once in a while. But simultaneously, some items may be updated by a background task, which means that the result of <code>compareTo()</code> changes. That's where the contract may be violated.</p>

<p>I understand, that the easiest answer would be, not to update the list during the sorting at all. But it's a mobile application. It has to be responsive and the user may refresh the list whenever he wants.</p>

<p>What would be an elegant approach to this problem? Using synchronizing or some kind of lock?</p>

<p>Thanks in advance.</p>
