MemoryNotificationInfo
MemoryNotificationInfo (메모리 알림 정보)
메모리 알림(memory notification)에 대한 정보를 담는 클래스예요. 메모리 풀의 메모리 사용량이 임계값을 초과하면 MemoryMXBean이 알림을 방출하는데, 그때 이 정보가 전달돼요.
본문
메모리 알림에는 다음의 정보가 포함돼요: 메모리 풀의 이름, 알림이 생성됐을 때의 메모리 사용량, 알림 생성 시점까지 메모리 사용량이 임계값을 넘은 횟수(사용 임계값 알림이면 usage threshold count, 컬렉션 임계값 알림이면 collection usage threshold count)예요.
MemoryNotificationInfo 객체를 나타내는 CompositeData가 알림의 user data에 저장돼요. from 메서드가 CompositeData를 MemoryNotificationInfo 객체로 변환해 줘요.
Notification notif; // MemoryMXBean이 방출한 알림
String notifType = notif.getType();
if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
|| notifType.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
CompositeData cd = (CompositeData) notif.getUserData();
MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
...
}
MemoryMXBean이 방출하는 알림 타입은 두 가지예요. 사용 임계값 초과 알림은 메모리 풀의 사용량이 증가해 사용 임계값에 도달하거나 초과하면 방출되고, 사용량이 임계값 아래로 돌아오기 전에는 다시 알림이 발생하지 않아요. 컬렉션 사용 임계값 초과 알림은 VM이 메모리 풀에서 미사용 객체를 재활용하는 작업을 수행한 뒤 사용량이 컬렉션 사용 임계값 이상이면 방출돼요. Java 1.5부터 제공돼요.