mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Fix IllegalMonitorStateException
When we unlock a lock the thread don't Held
This commit is contained in:
		
							parent
							
								
									57860793ff
								
							
						
					
					
						commit
						a441ce8ff4
					
				
					 1 changed files with 14 additions and 8 deletions
				
			
		| 
						 | 
					@ -41,6 +41,7 @@ import java.net.IDN;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.concurrent.TimeUnit;
 | 
				
			||||||
import java.util.concurrent.locks.ReentrantLock;
 | 
					import java.util.concurrent.locks.ReentrantLock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import app.fedilab.android.BaseMainActivity;
 | 
					import app.fedilab.android.BaseMainActivity;
 | 
				
			||||||
| 
						 | 
					@ -105,9 +106,9 @@ public class NotificationsHelper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        new Thread(() -> {
 | 
					        new Thread(() -> {
 | 
				
			||||||
            ReentrantLock lock = getLock(slug);
 | 
					            ReentrantLock lock = getLock(slug);
 | 
				
			||||||
            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()) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
                    MastodonNotificationsService mastodonNotificationsService = init(context, slugArray[1]);
 | 
					                    MastodonNotificationsService mastodonNotificationsService = init(context, slugArray[1]);
 | 
				
			||||||
                    Notifications notifications = new Notifications();
 | 
					                    Notifications notifications = new Notifications();
 | 
				
			||||||
                    Call<List<Notification>> notificationsCall;
 | 
					                    Call<List<Notification>> notificationsCall;
 | 
				
			||||||
| 
						 | 
					@ -135,19 +136,24 @@ public class NotificationsHelper {
 | 
				
			||||||
                        Runnable myRunnable = () -> onRetrieveNotifications(context, notifications, accountDb, last_notif_id);
 | 
					                        Runnable myRunnable = () -> onRetrieveNotifications(context, notifications, accountDb, last_notif_id);
 | 
				
			||||||
                        mainHandler.post(myRunnable);
 | 
					                        mainHandler.post(myRunnable);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					
 | 
				
			||||||
                } finally {
 | 
					                } finally {
 | 
				
			||||||
                    if (lock.isHeldByCurrentThread()) {
 | 
					                    if (lock.isHeldByCurrentThread()) {
 | 
				
			||||||
                        lock.unlock();
 | 
					                        lock.unlock();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }).start();
 | 
					        }).start();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static MastodonNotificationsService init(Context context, String instance) {
 | 
					    private static MastodonNotificationsService init(Context context, String instance) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final OkHttpClient okHttpClient = Helper.myOkHttpClient(context);
 | 
					        final OkHttpClient okHttpClient = new OkHttpClient.Builder()
 | 
				
			||||||
 | 
					                .readTimeout(60, TimeUnit.SECONDS)
 | 
				
			||||||
 | 
					                .connectTimeout(60, TimeUnit.SECONDS)
 | 
				
			||||||
 | 
					                .proxy(Helper.getProxy(context))
 | 
				
			||||||
 | 
					                .build();
 | 
				
			||||||
        Retrofit retrofit = new Retrofit.Builder()
 | 
					        Retrofit retrofit = new Retrofit.Builder()
 | 
				
			||||||
                .baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
 | 
					                .baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
 | 
				
			||||||
                .addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
 | 
					                .addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue