Merge pull request 'Set one lock per account for push notif' (#956) from s1m/Fedilab:push-multi-lock into develop
Reviewed-on: https://codeberg.org/tom79/Fedilab/pulls/956
This commit is contained in:
commit
57860793ff
|
@ -64,7 +64,18 @@ public class NotificationsHelper {
|
||||||
|
|
||||||
public static HashMap<String, List<String>> pushed_notifications = new HashMap<>();
|
public static HashMap<String, List<String>> pushed_notifications = new HashMap<>();
|
||||||
|
|
||||||
public static ReentrantLock lock = new ReentrantLock();
|
private static final HashMap<String, ReentrantLock> lockMap = new HashMap<>();
|
||||||
|
|
||||||
|
private static ReentrantLock getLock(String slug) {
|
||||||
|
synchronized (lockMap) {
|
||||||
|
if (lockMap.containsKey(slug)) {
|
||||||
|
return lockMap.get(slug);
|
||||||
|
}
|
||||||
|
ReentrantLock lock = new ReentrantLock();
|
||||||
|
lockMap.put(slug, lock);
|
||||||
|
return lock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized void task(Context context, String slug) throws DBException {
|
public static synchronized void task(Context context, String slug) throws DBException {
|
||||||
|
|
||||||
|
@ -93,6 +104,7 @@ public class NotificationsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
ReentrantLock lock = getLock(slug);
|
||||||
try {
|
try {
|
||||||
// fetch if we get the lock, or ignore, another thread is doing the job
|
// fetch if we get the lock, or ignore, another thread is doing the job
|
||||||
if (lock.tryLock()) {
|
if (lock.tryLock()) {
|
||||||
|
|
Loading…
Reference in New Issue