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

24
LINES

< > BotCompany Repo | #1006311 // smartTimerTask - create TimerTask with automatic fix for hibernation problem & automatic cancellation on program clean-up

JavaX fragment (include)

1  
// r may return false to cancel timer
2  
static TimerTask smartTimerTask(O r, java.util.Timer timer, long delay) {
3  
  ret SmartTimerTask(r, timer, delay, _threadInfo());
4  
}
5  
6  
srecord noeq SmartTimerTask(O r, java.util.Timer timer, long delay, O threadInfo) extends TimerTask {
7  
  long lastRun;
8  
  
9  
  public void run() {
10  
    if (!licensed())
11  
      timer.cancel();
12  
    else {
13  
      _threadInheritInfo(threadInfo);
14  
      temp tempActivity(r);
15  
      lastRun = fixTimestamp(lastRun);
16  
      long now = now();
17  
      if (now >= lastRun + delay*0.9) {
18  
        lastRun = now;
19  
        if (eq(false, pcallF(r)))
20  
          timer.cancel();
21  
      }
22  
    }
23  
  }
24  
}

Author comment

Began life as a copy of #1004684

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006311
Snippet name: smartTimerTask - create TimerTask with automatic fix for hibernation problem & automatic cancellation on program clean-up
Eternal ID of this version: #1006311/10
Text MD5: 2b83f745aab8832d15e5dcb5e1972889
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-26 13:35:15
Source code size: 660 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 526 / 592
Version history: 9 change(s)
Referenced in: [show references]