Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image Upload data

36
LINES

< > BotCompany Repo | #1013151 - FixedRateTimer - java.util.Timer that remembers what it is doing

JavaX fragment (include)

sclass FixedRateTimer extends java.util.Timer {
  *() { this(false); }
  *(bool daemon) { this(defaultTimerName(), daemon); }
  *(S name) { this(name, false); }
  *(S name, bool daemon) {
    super(name, daemon);
    _registerTimer(this);
  }
  
  L<Entry> entries = synchroList();
  
  srecord noeq Entry(TimerTask task, long firstTime, long period) {}
  
  // Note: not all methods overridden; only use these ones
  
  public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
    entries.add(new Entry(task, now()+delay, period));
    super.scheduleAtFixedRate(task, delay, period);
  }
  
  public void cancel() {
    entries.clear();
    super.cancel();
  }
  
  public int purge() {
    entries.clear();
    ret super.purge();
  }
  
  FixedRateTimer changeRate(int newPeriod) {
    O r = ((SmartTimerTask) first(entries).task).r;
    cancel();
    ret doEvery(newPeriod, r);
  }
}

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1013151
Snippet name: FixedRateTimer - java.util.Timer that remembers what it is doing
Eternal ID of this version: #1013151/11
Text MD5: e8c0ebd5a4bc2aa020080b096b150d9f
Author: stefan
Category: javax / timers
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-30 00:57:38
Source code size: 939 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 283 / 733
Version history: 10 change(s)
Referenced in: [show references]