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

34
LINES

< > BotCompany Repo | #1016395 // Emergency Restart on too much memory use

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 6517K of libraries. Click here for Pure Java version (9211L/48K).

!7

set flag OshiNotSticky.

cm whatever {
  transient SimpleLiveValue<S> lvStatus = stringLiveValue();
  switchable int max = 1024;
  switchable double interval = 10.0;
  
  visual jCenteredLiveValueLabel(lvStatus);

  start {
    lvStatus.set("Current threshold: " + max + " GB. You have 60s to change this value in this module's menu.");
    doEvery(interval, r checkIt); // allow 60 seconds after start to change max value
  }
  
  long usedMegabytes() {
    ret oshi_currentProcessResidentSize()/oneMegabyte();
  }
  
  void checkIt enter {
    long megabytes = usedMegabytes();
    lvStatus.set("Emergency restart enabled. Memory use: " + megabytes + "/" + max + " MB");
    if (megabytes >= max) {
      dm_gc();
      sleepSeconds(5);
      megabytes = usedMegabytes();
      if (megabytes >= max) {
        localMechLog("Emergency shutdowns", "Emergency shutdown at " + localDateWithSeconds() + " because of too much memory use ("+ megabytes + " MB)");
        dm_restartOS();
      }
    }
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016395
Snippet name: Emergency Restart on too much memory use
Eternal ID of this version: #1016395/14
Text MD5: b161e1739a881c1863ba1643f601660c
Transpilation MD5: 71f0a59829cc362584faf6771271d49b
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-05 00:52:11
Source code size: 1038 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 455 / 211272
Version history: 13 change(s)
Referenced in: [show references]