Skip to main content
. 2015 Jan 23;15(2):2565–2592. doi: 10.3390/s150202565

Algorithm 2 Adjust thread sleep time (ATST) algorithm, which is used to dynamically change the length of sleep time of a thread

Input: current data transmission interval transInterval, which is a double precision number time interval that the database storing sensor data transmission frequencies is queried
queryDBInterval, which is double precision number total time a thread has slept for sleptTime, which is a double precision number database connection string connectionString sensor identification sensorid
Output: void
Use: GetSqlConnection(connectionString) to get a database connection object using the given connection string
  CloseSqlConnection(conn) to close the database connection that connection object conn holds to release database resource
  GetTransIntervalBySensorID(conn, sensorID) to get sensor data transmission interval from database
  GetQueryDBIntervalFromCfg() to get database query interval from external configuration file
  ThreadSleep(timeInterval) to make a thread sleep for time timeInterval
Declare: None
Begin:
1:If (indicationInterval <= queryDBInterval) then
2:{ThreadSleep(transInterval);}
3:Else
4:{ThreadSleep(queryDBInterval);
5: conn = GetSqlConnection(connectionString);
6: double newTransInterval = 0.0;
7: If (conn! = null) then
8: {newTransInterval= GetTransIntervalBySensorID(conn, sensorid);
9: CloseSqlConnection(conn);}
10: End If
11: sleptTime = sleptTime + queryDBInterval;
12: If (newTransInterval > sleptTime) then
13: {newTransInterval = newTransInterval- sleptTime;
14: queryDBInterval = GetQueryDBIntervalFromCfg();
15: ATST(newTransInterval, queryDBInterval, sleptTime, connectionString, sensorid);}
16: End If}
17:End If
End