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

56
LINES

< > BotCompany Repo | #1033806 // AutoVMExit

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4687L/26K).

1  
sclass AutoVMExit extends TimerTask {
2  
  static boolean installed;
3  
  static boolean disabled;
4  
  int lastObjectCount = -1;
5  
  static java.util.Timer timer;
6  
  static int firstDelay = 30000;
7  
  static int delay = 5000;
8  
9  
  public static void install() {
10  
    if (!installed) {
11  
      installed = true;
12  
      if (!disabled) {
13  
        timer = new java.util.Timer("AutoVMExit");
14  
        timer.scheduleAtFixedRate(new AutoVMExit(), firstDelay, delay);
15  
      }
16  
    }
17  
  }
18  
19  
  /** Looks for objects that give us a reason to keep the VM alive.
20  
   *  Right now we count windows, tray icons and JavaFX stages. */
21  
  public void run() {
22  
    if (isHiddenVM()) ret;
23  
    
24  
    int objectCount = autoVMExit_visibleObjects();
25  
26  
    //System.out.println("Windows: " + objectCount);
27  
    if (objectCount == 0 && lastObjectCount == 0) {
28  
      System.out.println("AutoVMExit: No windows open or tray icons installed - exiting");
29  
      cleanKillVM();
30  
      //System.exit(0);
31  
    }
32  
    lastObjectCount = objectCount;
33  
  }
34  
35  
  public static void disable() {
36  
    disabled = true;
37  
    if (timer != null)
38  
      timer.cancel();
39  
  }
40  
41  
  public static int getFirstDelay() {
42  
    return firstDelay;
43  
  }
44  
45  
  public static void setFirstDelay(int firstDelay) {
46  
    AutoVMExit.firstDelay = firstDelay;
47  
  }
48  
49  
  public static int getDelay() {
50  
    return delay;
51  
  }
52  
53  
  public static void setDelay(int delay) {
54  
    AutoVMExit.delay = delay;
55  
  }
56  
}

Author comment

Began life as a copy of #1007192

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033806
Snippet name: AutoVMExit
Eternal ID of this version: #1033806/1
Text MD5: bf5ab8d49555b61090a2813c33e30dd7
Transpilation MD5: ba0eefbbe2472e76f996476054ac2e33
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-05 05:10:54
Source code size: 1443 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 177 / 255
Referenced in: [show references]