/*
(non-Javadoc)
@see org.overture.vdmj.scheduler.ISchedulableThread#run()
772630
public void run()
	{
		try
		{
			reschedule(null, null);
			body();
		} finally
		{
			setState(RunState.COMPLETE);
			resource.unregister(this);
			BasicSchedulableThread.remove(this);
			getThread().setName("pool-" + getThread().getId() + "-thread-");
		}
	}
441687
@Override
	public synchronized void run()
	{
		List<ActiveObject> inactiveList = new ArrayList<>();
		try
		{
			log.debug("Starting activity watchdog (wakeUpInterval="+WAKE_UP_INTERVAL+"ms)");
			while (!stop)
			{
				wait(WAKE_UP_INTERVAL);
				if (stop)
					return;
				
				// Check watchlist
				long now = System.currentTimeMillis();
				synchronized (watchList)
				{
					for (int i = 0; i < watchList.size(); i++)
					{
						WeakReference<ActiveObject> weakRef = watchList.get(i);
						ActiveObject obj = weakRef.get();
						if (obj == null)
						{
							// Object was garbage collected, remove and continue
							watchList.remove(i--);
							continue;
						}
					
						// Check object activity
						if ((now - obj.getLastActivity()) > obj.getTimeoutDelay())
						{
							log.trace("Marking object as inactive : "+obj);
							inactiveList.add(obj);
						}
					}
				}
				
				// Process inactive objects
				for (int n = 0; n < inactiveList.size(); n++)
				{
					ActiveObject obj = inactiveList.get(n);
					try
					{
						if (!obj.onActivityTimeout())
							inactiveList.remove(n--);
					}
					catch (Exception e)
					{
						log.error("Error notifying an inactive object",e);
					}
				}
				
				// Remove expired objects
				synchronized (watchList)
				{
					for(int n=0;n<inactiveList.size();n++)
					{
						ActiveObject targetObj = inactiveList.get(n);
						for (int i = 0; i < watchList.size(); i++)
						{
							WeakReference<ActiveObject> weakRef = watchList.get(i);
							ActiveObject obj = weakRef.get();
							if (obj == targetObj)
							{
								log.trace("Removing inactive object from watch list : "+targetObj);
								watchList.remove(i--);
								break;
							}
						}
					}
				}
		
				// Clear inactive object list
				inactiveList.clear();
			}
			log.debug("Activity watchdog stopped");
		}
		catch (Throwable e)
		{
			log.error("Activity watchdog failed",e);
		}
	}
1043563
@Override
  public void run()
  {
    try {
      runImpl();
    } catch (final Throwable e) {
      // env/0203 vs env/0206
      if (e instanceof DisplayableException)
        log.warning(e.getMessage());
      else
        log.warning(e.toString());
      
      _exception = e;
    } finally {
      notifyComplete();
    }
  }
535065
@Override
    public void run() {

        final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "run", "alarm");
        }

        if (isTracingEnabled && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "run: alarm, Pool contents ==> " + this.toString());
            Tr.debug(this, tc, "reaperThreadStarted: ", reaperThreadStarted);
        }

        if (needToReclaimConnections() || needToReclaimTLSConnections()) {
            // Create thread to reclaim connections
            startReclaimConnectionThread();
        }

        if (isTracingEnabled && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "run: alarm, Pool contents ==> " + this.toString());
            Tr.debug(this, tc, "reaperThreadStarted: ", reaperThreadStarted);
        }

        synchronized (amLockObject) {
            if (this.agedTimeout < 1) {
                if ((totalConnectionCount.get() > minConnections) && alarmThreadCounter.get() >= 0) {
                    createReaperAlarm();
                } else {
                    if (alarmThreadCounter.get() > 0)
                        alarmThreadCounter.decrementAndGet();
                    if (isTracingEnabled && tc.isDebugEnabled())
                        Tr.debug(tc, "Alarm thread was NOT started. Number of alarm threads is " + alarmThreadCounter.get());
                }
            } else {
                if (totalConnectionCount.get() > 0 && alarmThreadCounter.get() >= 0) {
                    createReaperAlarm();
                } else {
                    if (alarmThreadCounter.get() > 0)
                        alarmThreadCounter.decrementAndGet();
                    if (isTracingEnabled && tc.isDebugEnabled())
                        Tr.debug(tc, "Alarm thread was NOT started. Number of alarm threads is " + alarmThreadCounter.get());
                }
            }
        }

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "run");
        }

    }
550773
@Override
    public void run() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.entry(tc, "run");
        }
        pm.executeTask();
        pm.reaperThreadStarted = false;
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.exit(tc, "run");
        }

    }
33093
@Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                int count = collectionService.commitAnnotations(ANNOTATION_CHUNK_SIZE, TIMEOUT);

                if (count > 0) {
                    LOGGER.info(MessageFormat.format("Committed {0} annotations.", count));
                    jobCounter.addAndGet(count);
                }
                Thread.sleep(POLL_INTERVAL_MS);
            } catch (InterruptedException ie) {
                LOGGER.info("Execution was interrupted.");
                Thread.currentThread().interrupt();
                break;
            } catch (Throwable ex) {
                LOGGER.info("Error occurred while committing annotations. Reason {}", ex.toString());
            }
        }
        LOGGER.warn(MessageFormat.format("Annotation committer thread interrupted. {} annotations committed by this thread.", jobCounter.get()));
        collectionService.dispose();
        monitorService.dispose();
    }
1338633
@Override
	public final void run() {

		LOGGER.debug("Executing " + getClass().getSimpleName());
		markAsInProgress();

		if (!Lists.isNullOrEmpty(listeners)) {
			Runnable startUseCaseRunnable = new Runnable() {
				@Override
				public void run() {
					for (UseCaseListener listener : listeners) {
						notifyUseCaseStart(listener);
					}
				}
			};
			if (handler != null) {
				handler.post(startUseCaseRunnable);
			} else {
				startUseCaseRunnable.run();
			}
		}

		Trace trace = null;
		if (timingTrackingEnabled()) {
			trace = TraceHelper.startTrace(getClass());
		}

		try {

			LOGGER.debug("Started " + getClass().getSimpleName());
			executionTime = null;
			startTime = DateUtils.nowMillis();
			doExecute();
			executionTime = DateUtils.nowMillis() - startTime;
			LOGGER.debug("Finished " + getClass().getSimpleName() + ". Execution time: " + DateUtils.formatDuration(executionTime));

			if (trace != null) {
				trace.putAttribute("result", "success");
				trace.incrementMetric("successes", 1);
			}

			markAsSuccessful();

			if (!Lists.isNullOrEmpty(listeners)) {
				Runnable finishedUseCaseRunnable = new Runnable() {
					@Override
					public void run() {
						for (UseCaseListener listener : listeners) {
							notifyFinishedUseCase(listener);
						}
						markAsNotified();
					}
				};
				if (handler != null) {
					handler.post(finishedUseCaseRunnable);
				} else {
					finishedUseCaseRunnable.run();
				}
			}

		} catch (RuntimeException e) {
			if (trace != null) {
				trace.putAttribute("result", "failure");
				trace.incrementMetric("failures", 1);
			}
			final AbstractException abstractException = wrapException(e);
			markAsFailed(abstractException);
			logHandledException(abstractException);

			if (!Lists.isNullOrEmpty(listeners)) {
				Runnable finishedFailedUseCaseRunnable = new Runnable() {
					@Override
					public void run() {
						for (UseCaseListener listener : listeners) {
							notifyFailedUseCase(abstractException, listener);
						}
						markAsNotified();
					}
				};
				if (handler != null) {
					handler.post(finishedFailedUseCaseRunnable);
				} else {
					finishedFailedUseCaseRunnable.run();
				}
			}
		} finally {
			if (trace != null) {
				trace.stop();
			}
		}
	}
158715
@Override
    public void run() {
        try {
            ScheduledEventQueue queue = ScheduledEventQueue.getSingleton();
            int batch_size = PropertyManager.getIntegerProperty(PropertyNames.SCHEDULED_EVENTS_BATCH_SIZE, 1000);
            int count = 0;
            Date now = new Date(DatabaseAccess.getCurrentTime());
            logger.log(LogLevel.TRACE, "Processing scheduled events at: " + now);
            ScheduledEvent event = queue.getNextReadyEvent(now);
            while (event!=null && count < batch_size) {
                count++;
                queue.processEvent(event, now);
                event = queue.getNextReadyEvent(now);
            }
        }
        catch (Throwable t) {
            logger.severeException(t.getMessage(), t);
        }
    }
57708
@Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        super.subjectRepository.createSubject(this.subject, new SubjectRepository.SubjectUseCase() {
            @Override
            public void onMissionAccomplished(final Subject subject) {
                CreateSubjectUseCaseImp.super.mainThread.post(new Runnable() {
                    @Override
                    public void run() {
                        callback.onMissionAccomplished(subject);
                    }
                });
            }

            @Override
            public void onError(final SubjectException subjectException) {
                CreateSubjectUseCaseImp.super.mainThread.post(new Runnable() {
                    @Override
                    public void run() {
                        callback.onError(subjectException);
                    }
                });
            }
        });
    }
558977
private void run(final RunNode current) {
        try {
            current.runnable.run();
        } catch (final Throwable thrown) {
            reportFailure(Thread.currentThread(), thrown);
        }
    }
845576
public void run()
    {
        try
        {
            if (!thread.compareAndSet(null, Thread.currentThread()))
            {
                return;
            }

            final IdleStrategy idleStrategy = this.idleStrategy;
            final Agent agent = this.agent;
            try
            {
                agent.onStart();
            }
            catch (final Throwable throwable)
            {
                errorHandler.onError(throwable);
                isRunning = false;
            }

            while (isRunning)
            {
                if (doDutyCycle(idleStrategy, agent))
                {
                    break;
                }
            }

            try
            {
                agent.onClose();
            }
            catch (final Throwable throwable)
            {
                errorHandler.onError(throwable);
            }
        }
        finally
        {
            isClosed = true;
        }
    }
6295
@Override
    public synchronized void run(){
        Date now = new Date();
        if ( !cache.isEmpty() &&
                ((cache.size() > cacheSize - 1) || (now.getTime() - lastCacheAccess.getTime() > cacheMillis))) {
            try {
                flush();
            } catch (RepositoryException e) {
                log.error(e.getLocalizedMessage());
                throw new RuntimeException(e);
            } catch (MalformedQueryException e) {
                log.error(e.getLocalizedMessage());
                throw new RuntimeException(e);
            } catch (UpdateExecutionException e) {
                log.error(e.getLocalizedMessage());
                throw new RuntimeException(e);
            } catch (IOException e) {
                log.error(e.getLocalizedMessage());
                throw new RuntimeException(e);
            }
        }
    }
1141605
public static void runIntoJAT(final JRebirthRunnable runnable) {
        if (Platform.isFxApplicationThread()) {
            // We are into a JAT so just run it synchronously
            runnable.run();
        } else {
            // The runnable will be run into the JAT during the next round
            Platform.runLater(runnable);
        }
    }
890827
@SuppressWarnings("InfiniteLoopStatement")
  @Override
  public void run() {
    try {
      while (true) {
        try {
          cleanUp(queue.remove());
        } catch (InterruptedException e) { /* ignore */ }
      }
    } catch (ShutDown shutDown) { /* ignore */ }
  }
312075
public void run() {
		
		final TimerTaskData taskData = task.getData();
		final Serializable taskID = taskData.getTaskID();
		
		if (logger.isDebugEnabled()) {
			logger.debug("Cancelling timer task for timer ID "+taskID);
		}
		
		scheduler.getLocalRunningTasksMap().remove(taskID);
		
		try {
			task.cancel();					
		}
		catch (Throwable e) {
			logger.error(e.getMessage(),e);
		}
	}
1055393
@Override
	public void run() {

		final long currentTime = System.currentTimeMillis();

		synchronized (this.collectedEvents) {

			final Iterator<JobID> it = this.collectedEvents.keySet().iterator();
			while (it.hasNext()) {

				final JobID jobID = it.next();
				final List<AbstractEvent> eventList = this.collectedEvents.get(jobID);
				if (eventList == null) {
					continue;
				}

				final Iterator<AbstractEvent> it2 = eventList.iterator();
				while (it2.hasNext()) {

					final AbstractEvent event = it2.next();
					// If the event is older than TIMERTASKINTERVAL, remove it
					if ((event.getTimestamp() + this.timerTaskInterval) < currentTime) {
						archiveEvent(jobID, event);
						it2.remove();
					}
				}

				if (eventList.isEmpty()) {
					it.remove();
				}
			}
		}

		synchronized (this.recentJobs) {

			final Iterator<Map.Entry<JobID, RecentJobEvent>> it = this.recentJobs.entrySet().iterator();
			while (it.hasNext()) {

				final Map.Entry<JobID, RecentJobEvent> entry = it.next();
				final JobStatus jobStatus = entry.getValue().getJobStatus();

				// Only remove jobs from the list which have stopped running
				if (jobStatus != JobStatus.FINISHED && jobStatus != JobStatus.CANCELED
					&& jobStatus != JobStatus.FAILED) {
					continue;
				}

				// Check time stamp of last job status update
				if ((entry.getValue().getTimestamp() + this.timerTaskInterval) < currentTime) {
					archiveJobevent(entry.getKey(), entry.getValue());
					it.remove();
					synchronized (this.recentManagementGraphs) {
						archiveManagementGraph(entry.getKey(), this.recentManagementGraphs.get(entry.getKey()));
						this.recentManagementGraphs.remove(entry.getValue());
					}
					synchronized (this.recentNetworkTopologies) {
						archiveNetworkTopology(entry.getKey(), this.recentNetworkTopologies.get(entry.getKey()));
						this.recentNetworkTopologies.remove(entry.getValue());
					}
				}
			}
		}
	}
1208169
@Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {

        }
        //TODO replace me with a timer task
        while (running) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (needsDataRefresh) {
                if (System.currentTimeMillis() - lastMovement > 500) {
                    generateMap();
                    needsDataRefresh = false;
                }
            }
        }
    }