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

22
LINES

< > BotCompany Repo | #1013399 // onGCNotification

JavaX fragment (include)

import javax.management.*;
import javax.management.openmbean.CompositeData;
import com.sun.management.GarbageCollectionNotificationInfo;
import com.sun.management.GcInfo;

static AutoCloseable onGCNotification(final VF1<GarbageCollectionNotificationInfo> theListener) {
  final NotificationListener listener = new NotificationListener {
    public void handleNotification(Notification notification, O handback) {
      // extract garbage collection information from notification.
      GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
      pcallF(theListener, gcInfo);
    }
  };

  for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans())
    ((NotificationEmitter) gcBean).addNotificationListener(listener, null, null);
    
  ret autoCloseable {
    for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans())
      ((NotificationEmitter) gcBean).removeNotificationListener(listener, null, null);
  };
}

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: #1013399
Snippet name: onGCNotification
Eternal ID of this version: #1013399/8
Text MD5: 973f9d0004afb0a187e8e8a6ee7d9048
Author: stefan
Category: javax / gc / monitoring
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-28 14:12:44
Source code size: 1059 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 359 / 429
Version history: 7 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)