4 Replies - 502 Views - Last Post: 30 March 2013 - 08:20 PM Rate Topic: -----

#1 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 229
  • Joined: 23-January 09

Quick question on timer.

Posted 28 March 2013 - 07:55 PM

Hey guys I have some questions regarding timer.

I have a program that requires checking the database every 1hour,2hours and 3 hours for Customers A, B and C

So it is something like:
Every 1 hours, customer A will read data from database,
Every 2 hours customer B will read data from database (customer A will now read the 2nd time since it is 2hours)

Since timer accepts Timer(1hour)

does it mean I will need multiple instance if I need to do what I want above? An instance for every customer that have different time when they need to read the database.

So:

Timer cust1 = new Timer(1hour)
Timer cust2 = new Timer(2hours)
Timer cust3 = new Timer(3hours)

I do not need help with code here but I will need help on which is the best way to do it?

Are there any side effected to creating multiple timer instance? I would expect to have a maximum of 10 timers running simultaneously...if the best way is to create multiple instance.

How would you implement it if you were me?

Is This A Good Question/Topic? 0
  • +

Replies To: Quick question on timer.

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,500
  • Joined: 29-May 08

Re: Quick question on timer.

Posted 28 March 2013 - 08:03 PM

Which timer are you talking about? as there as several different timers in the framework.
Was This Post Helpful? 0
  • +
  • -

#3 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 229
  • Joined: 23-January 09

Re: Quick question on timer.

Posted 28 March 2013 - 08:05 PM

That will be system.timers.timers (not the threading one)
Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Quick question on timer.

Posted 28 March 2013 - 09:36 PM

I would just use one timer and counters for each customer. When the customer counter mod hour is zero, you do whatever you need to do. You also increment all the counters at this time.
Was This Post Helpful? 1
  • +
  • -

#5 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 229
  • Joined: 23-January 09

Re: Quick question on timer.

Posted 30 March 2013 - 08:20 PM

Well I have follow the solution and use 1 timer and did something like:

in pseudo code:
static int minutesPassed = 0;
public Test(){
 t = new Timer(60000)//1min
 
}

public void timer_elapse(){

//since timer is set to run every 1min it will increment by 1 each time. Every 24 hours or 1440mins //it will reset to //0 or 1 (not too sure about this.)
   minutesPassed ++ ; 

   if(minutesPassed == 1440){
     //1440 mins = 12:00 AM
     minutesPassed = 0;
   }

//custA check every 20 mins
//custB check every 120 mins

   if(minutesPassed % custA.getTime() == 0){
     connectDB(custA);
   }else if(minutesPassed  % custB.getTime() ==0){
     connectDB(custB)
   }
 
}


This post has been edited by aklo: 30 March 2013 - 08:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1