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).

1  
!7
2  
3  
// Note: Deadlock solving happens in OS main too, so it will not be
4  
// lost if GC is turned off here.
5  
6  
cmodule2 GarbageCollection {
7  
  bool on = true;
8  
  transient IF0<Bool> cond = () -> on;
9  
  
10  
  start {
11  
    doEvery(1.0, 60.0, r updateMe);
12  
  }
13  
  
14  
  visualize {
15  
    JLabel lblTime = jCenteredLabel(" ");
16  
    awtEvery(lblTime, 1000, r {
17  
      long last = lastRegularGC();
18  
      setText(lblTime, last == 0 ? "No GC yet"
19  
        : "Time since last GC: " + iround(elapsedSeconds_timestamp(last)) + " s");
20  
    });
21  
    ret vstackWithSpacing(
22  
      toolTip("On = Perform a Java garbage collection every minute", centerCheckBox(dm_fieldCheckBox("GC On", 'on))),
23  
      lblTime);
24  
  }
25  
  
26  
  void update {
27  
    //print("GC: " + on);
28  
    if (dm_osHasField gc_subcondition()) {
29  
      // new method - keeps weak hash map cleaning
30  
      if (dm_getOS gc_subcondition() != cond) {
31  
        dm_setOS gc_subcondition(cond);
32  
       infoBoxAndProgramLog((on ? "Enabling" : "Disabling") + " Garbage Collection");
33  
      }
34  
      updateModuleName();
35  
    } else {
36  
      print("Legacy method");
37  
      // legacy method
38  
      bool has = hasRegularGC();
39  
      if (has != on) {
40  
        infoBoxAndProgramLog((on ? "Enabling" : "Disabling") + " Garbage Collection");
41  
        if (on) regularGC_firstDelay(1000); else noRegularGC();
42  
      }
43  
    }
44  
  }
45  
  
46  
  void updateModuleName {
47  
    setModuleName("Garbage collector is " + (on ? "On" : "Off"));
48  
  }
49  
}

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: 507 / 66711
Version history: 23 change(s)
Referenced in: [show references]