1 | import javax.management.*; |
2 | import javax.management.openmbean.CompositeData; |
3 | import com.sun.management.GarbageCollectionNotificationInfo; |
4 | import com.sun.management.GcInfo; |
5 | |
6 | static AutoCloseable onGCNotification(final VF1<GarbageCollectionNotificationInfo> theListener) { |
7 | final NotificationListener listener = new NotificationListener { |
8 | public void handleNotification(Notification notification, O handback) { |
9 | // extract garbage collection information from notification. |
10 | GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()); |
11 | pcallF(theListener, gcInfo); |
12 | } |
13 | }; |
14 | |
15 | for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) |
16 | ((NotificationEmitter) gcBean).addNotificationListener(listener, null, null); |
17 | |
18 | ret autoCloseable { |
19 | for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) |
20 | ((NotificationEmitter) gcBean).removeNotificationListener(listener, null, null); |
21 | }; |
22 | } |
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: | 368 / 438 |
Version history: | 7 change(s) |
Referenced in: | [show references] |