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

26
LINES

< > BotCompany Repo | #1013395 // Test GarbageCollectorMXBean 3 (GC notifications, OK)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (3148L/20K).

1  
!7
2  
3  
import javax.management.*;
4  
import javax.management.openmbean.CompositeData;
5  
import com.sun.management.GarbageCollectionNotificationInfo;
6  
7  
p {
8  
  wordWrapConsole();
9  
  NotificationListener listener = new NotificationListener {
10  
    @Override
11  
    public void handleNotification(Notification notification, O handback) {
12  
      print("type: " + notification.getType());
13  
      if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
14  
        // extract garbage collection information from notification.
15  
        GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
16  
        //print("Cause: " + gcInfo.getGcCause();
17  
        pnlStruct(callAllMethodsInInterface(gcInfo, GarbageCollectionNotificationInfo.class);
18  
        print();
19  
      }
20  
    }
21  
  };
22  
23  
  // register our listener with all gc beans
24  
  for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans())
25  
    ((NotificationEmitter) gcBean).addNotificationListener(listener, null, null);
26  
}

Author comment

Began life as a copy of #1013393

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1013395
Snippet name: Test GarbageCollectorMXBean 3 (GC notifications, OK)
Eternal ID of this version: #1013395/7
Text MD5: 6e9892bfcf15be5231339dc19d4995ab
Transpilation MD5: c0fcc53e7bb6e0de5ea2bba2fd5db30f
Author: stefan
Category: javax / gc / monitoring
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-07 16:45:03
Source code size: 1100 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 486 / 1132
Version history: 6 change(s)
Referenced in: [show references]