All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dg.libs.rest.services.ThreadCountObserver Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
/**
 *
 */
package com.dg.libs.rest.services;

import java.util.LinkedList;

import com.araneaapps.android.libs.logger.ALog;

/** @author darko.grozdanovski */
public abstract class ThreadCountObserver {

  public static final String TAG = ThreadCountObserver.class.getSimpleName();

  public abstract void onThreadsFinished();

  public abstract void newRunnableRegistered();

  LinkedList observerList = new LinkedList();

  public void registerRunnable(final Runnable r) {
    synchronized (observerList) {
      observerList.add(r);
    }
    newRunnableRegistered();
    ALog.d(TAG, "observer list size on register: " + observerList.size());
  }

  public void unregisterRunnable(final Runnable r) {
    synchronized (observerList) {
      observerList.remove(r);
    }
    ALog.d(TAG, "observer list size on unregister: " + observerList.size());
    if (observerList.size() == 0) {
      ALog.d(TAG, "observer calling finish method");
      onThreadsFinished();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy