Skip to content

Commit

Permalink
Moving log statement into separate thread when aborting polls.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrypacker committed Feb 29, 2016
1 parent 065491c commit 54ee631
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions Core/src/com/serotonin/m2m2/rt/dataSource/PollingDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ abstract public class PollingDataSource extends DataSourceRT implements TimeoutC

private TimerTask timerTask;
private volatile Thread jobThread;
private long jobThreadStartTime;

private final AtomicBoolean lastPollSuccessful = new AtomicBoolean();
private final AtomicLong successfulPolls = new AtomicLong();
Expand Down Expand Up @@ -111,22 +110,9 @@ public void incrementUnsuccessfulPolls(long time) {
@Override
public void scheduleTimeout(long fireTime) {
long startTs = System.currentTimeMillis();
//TODO Remove when done testing.
//System.out.println("Scheduled: " + fireTime + " time: " + startTs + " task: " + this.timerTask.getTaskId() + " dspoll");
if(jobThreadStartTime == fireTime){
LOG.warn("Poll at same time: " + fireTime);
}
//End remove when done testing

//Check to see if this poll is running after it's next poll time, i.e. polls are backing up
if((cronPattern == null)&&((startTs - fireTime) > pollingPeriodMillis)){
//Get the stack trace
// StackTraceElement[] trace = oldJobThread.getStackTrace();
// StringBuilder builder = new StringBuilder("\n");
// for(StackTraceElement e : trace){
// builder.append(e.getClassName() + "." + e.getMethodName() + " " + e.getLineNumber() + "\n");
// }

// There is another poll still running, so abort this one.
LOG.warn(vo.getName() + ": poll scheduled at " + Functions.getFullMilliSecondTime(fireTime)
+ " aborted because its start time of " + Functions.getFullMilliSecondTime(startTs) + " is more than the time allocated for in its poll period."); //+ builder.toString());
Expand Down Expand Up @@ -155,7 +141,6 @@ public String getDescription() {

try {
jobThread = Thread.currentThread();
jobThreadStartTime = fireTime;

// Check if there were changes to the data points list.
updateChangedPoints(fireTime);
Expand Down Expand Up @@ -230,9 +215,6 @@ protected void updateChangedPoints(long fireTime) {
@Override
public void rejected(final RejectedTaskReason reason){

LOG.warn(vo.getName() + ": poll scheduled at " + Functions.getFullMilliSecondTime(reason.getScheduledExecutionTime())
+ " aborted because " + reason.getDescription());

//Raise Event that Task Was Rejected
switch(reason.getCode()){
case RejectedTaskReason.CURRENTLY_RUNNING:
Expand All @@ -241,6 +223,8 @@ public void rejected(final RejectedTaskReason reason){

@Override
public void execute() {
LOG.warn(vo.getName() + ": poll scheduled at " + Functions.getFullMilliSecondTime(reason.getScheduledExecutionTime())
+ " aborted because " + reason.getDescription());
incrementUnsuccessfulPolls(reason.getScheduledExecutionTime());
}

Expand Down

0 comments on commit 54ee631

Please sign in to comment.