Fix race conditions on SQLiteScoreList

This commit is contained in:
2017-06-10 16:48:53 -04:00
parent e06ace9ea8
commit fe1513bb64
4 changed files with 69 additions and 27 deletions

View File

@@ -81,7 +81,7 @@ public abstract class ScoreList implements Iterable<Score>
* @param timestamp the timestamp of a day
* @return score value for that day
*/
public final synchronized int getValue(long timestamp)
public synchronized final int getValue(long timestamp)
{
compute(timestamp, timestamp);
Score s = getComputedByTimestamp(timestamp);

View File

@@ -100,7 +100,8 @@ public class SQLiteScoreList extends ScoreList
@NonNull
@Override
public List<Score> getByInterval(long fromTimestamp, long toTimestamp)
public synchronized List<Score> getByInterval(long fromTimestamp,
long toTimestamp)
{
check(habit.getId());
compute(fromTimestamp, toTimestamp);
@@ -137,7 +138,7 @@ public class SQLiteScoreList extends ScoreList
}
@Override
public int getTodayValue()
public synchronized int getTodayValue()
{
if (cache == null || cache.expired())
cache = new CachedData(super.getTodayValue());
@@ -146,7 +147,7 @@ public class SQLiteScoreList extends ScoreList
}
@Override
public void invalidateNewerThan(long timestamp)
public synchronized void invalidateNewerThan(long timestamp)
{
cache = null;
invalidateStatement.bindLong(1, habit.getId());