public void run(){
  _setRunning(true);
  while (_keepRunning()) {
    if (_activityCount() > 0) {
      long currentTime=System.currentTimeMillis();
      long t=-1;
synchronized (this) {
        for (int i=0; i < m_activities.size(); i++) {
          Activity a=(Activity)m_activities.get(i);
          m_tmp.add(a);
          if (currentTime >= a.getStopTime()) {
            m_activities.remove(i--);
            a.setScheduled(false);
          }
        }
        if (m_activities.size() == 0) {
          m_nextTime=Long.MAX_VALUE;
        }
      }
      for (int i=0; i < m_tmp.size(); i++) {
        Activity a=(Activity)m_tmp.get(i);
        long s=a.runActivity(currentTime);
        t=(s < 0 ? t : t < 0 ? s : Math.min(t,s));
      }
      m_tmp.clear();
      if (t == -1)       continue;
      try {
synchronized (this) {
          wait(t);
        }
      }
 catch (      InterruptedException e) {
      }
    }
 else {
      try {
synchronized (this) {
          wait();
        }
      }
 catch (      InterruptedException e) {
      }
    }
  }
}

public void run ( ) { _setRunning ( true ) ; while ( _keepRunning ( ) ) { if ( _activityCount ( ) > 0 ) { long currentTime = System . currentTimeMillis ( ) ; long t = - 1 ; synchronized ( this ) { for ( int i = 0 ; i < m_activities . size ( ) ; i ++ ) { Activity a = ( Activity ) m_activities . get ( i ) ; m_tmp . add ( a ) ; if ( currentTime >= a . getStopTime ( ) ) { m_activities . remove ( i -- ) ; a . setScheduled ( false ) ; } } if ( m_activities . size ( ) == 0 ) { m_nextTime = Long . MAX_VALUE ; } } for ( int i = 0 ; i < m_tmp . size ( ) ; i ++ ) { Activity a = ( Activity ) m_tmp . get ( i ) ; long s = a . runActivity ( currentTime ) ; t = ( s < 0 ? t : t < 0 ? s : Math . min ( t , s ) ) ; } m_tmp . clear ( ) ; if ( t == - 1 ) continue ; try { synchronized ( this ) { wait ( t ) ; } } catch ( InterruptedException e ) { } } else { try { synchronized ( this ) { wait ( ) ; } } catch ( InterruptedException e ) { } } } }
main scheduling thread loop . this is automatically started upon initialization of the activitymanager .
