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

49
LINES

< > BotCompany Repo | #1019940 // Garbage Collector [GC] On/Off

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

Uses 1113K of libraries. Click here for Pure Java version (7744L/39K).

!7

// Note: Deadlock solving happens in OS main too, so it will not be
// lost if GC is turned off here.

cmodule2 GarbageCollection {
  bool on = true;
  transient IF0<Bool> cond = () -> on;
  
  start {
    doEvery(1.0, 60.0, r updateMe);
  }
  
  visualize {
    JLabel lblTime = jCenteredLabel(" ");
    awtEvery(lblTime, 1000, r {
      long last = lastRegularGC();
      setText(lblTime, last == 0 ? "No GC yet"
        : "Time since last GC: " + iround(elapsedSeconds_timestamp(last)) + " s");
    });
    ret vstackWithSpacing(
      toolTip("On = Perform a Java garbage collection every minute", centerCheckBox(dm_fieldCheckBox("GC On", 'on))),
      lblTime);
  }
  
  void update {
    //print("GC: " + on);
    if (dm_osHasField gc_subcondition()) {
      // new method - keeps weak hash map cleaning
      if (dm_getOS gc_subcondition() != cond) {
        dm_setOS gc_subcondition(cond);
       infoBoxAndProgramLog((on ? "Enabling" : "Disabling") + " Garbage Collection");
      }
      updateModuleName();
    } else {
      print("Legacy method");
      // legacy method
      bool has = hasRegularGC();
      if (has != on) {
        infoBoxAndProgramLog((on ? "Enabling" : "Disabling") + " Garbage Collection");
        if (on) regularGC_firstDelay(1000); else noRegularGC();
      }
    }
  }
  
  void updateModuleName {
    setModuleName("Garbage collector is " + (on ? "On" : "Off"));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019940
Snippet name: Garbage Collector [GC] On/Off
Eternal ID of this version: #1019940/24
Text MD5: bbede49dc736c3338373b618f754be16
Transpilation MD5: 468c80601bcf774dc125f8923451bc63
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: 2021-06-27 00:38:56
Source code size: 1461 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 410 / 66581
Version history: 23 change(s)
Referenced in: [show references]