7.12.2 Implementing to obtain statistics of the Explicit Memory Management functionality
This section describes the implementation for obtaining statistics of the Explicit Memory Management functionality in your application. You can debug and analyze failures by obtaining statistics.
If you have implemented the Explicit Memory Management functionality in your application, you can obtain the following information as statistics:
-
Status of using the Explicit heap
-
Explicit memory block size represented by the ExplicitMemory instance
-
Information of Explicit memory block
Also, you can execute the following processes as processes associated with obtaining statistics:
-
Setting and obtaining name of Explicit memory block
-
Determining whether Explicit memory block is processable
-
Determining whether Explicit memory block can be reserved for release
This subsection describes the implementation of each process that uses the Explicit Memory Management functionality API.
- Organization of this subsection
(1) Obtaining the status of using the Explicit heap
This point describes how to obtain information of the Explicit heap. The Explicit heap represents all Explicit memory blocks. For details on how to obtain information of each Explicit memory block, see (3) Obtaining information of Explicit memory block.
- Used API
-
getMemoryUsage()
This API creates an instance of the java.lang.management.MemoryUsage class and returns the instance.
Information described in the following table is set in each field in the returned instance, as the information at the time of creating the instance.
The following figure shows the values shown by each field.
|
|
(2) Explicit memory block size represented by ExplicitMemory instance
Obtain the Explicit memory block size that is represented by the ExplicitMemory instance, as the status of using Explicit memory block. By using the Explicit memory block size, you can check the status of using the memory in the Explicit Memory Management functionality.
- Used API
-
-
freeMemory()
-
usedMemory()
-
totalMemory()
-
The following table describes the status of using Explicit memory block that you can obtain with each API. You can obtain the size as a long type value.
|
API |
Status of using Explicit memory block that you can obtain |
|---|---|
|
freeMemory() |
Usable memory size (units: bytes) |
|
usedMemory() |
Used memory size (units: bytes) |
|
totalMemory() |
Total secured size (units: bytes) |
The following figure shows the values that you can obtain with each API.
|
|
(3) Obtaining information of Explicit memory block
Obtain the number of the Explicit memory blocks that have an entity in the Explicit heap. The released or invalid Explicit memory blocks are not targeted. If you obtain the number of valid Explicit memory blocks, you can calculate the average memory size used in each Explicit memory block.
- Used API
-
countExplicitMemories()
This API counts the number of memory blocks in the Explicit heap and returns it as a value of the int type. The Explicit memory blocks meeting the conditions are targeted for counting.
-
Valid Explicit memory blocks
Valid Explicit memory blocks are targeted irrespective of their sub-status (Enable or Disable).
-
Explicit memory blocks that are reserved for releasing
(4) Setting and obtaining name of the Explicit memory block
You can set name to an instance corresponding to the Explicit memory block. You can also obtain the set name. An Explicit memory block instance has a name for easy handling in an application. An instance becomes easy to use if you set a name to it.
The set value is also output in an event log of the Explicit Memory Management functionality.
- Used API
-
-
setName()
This API sets name.
-
getName()
This API obtains name.
-
If you do not set a name in your application, the following default name is set.
BasicExplicitMemory-<ID>
ID is a value managed by JavaVM.
- Important note
-
When naming an Explicit memory block, do not use a name starting with "CCC#". The J2EE server uses names starting with "CCC#".
The J2EE server uses the following Explicit memory block names:
(5) Determining whether the Explicit memory block is processable
The Explicit memory block might become non-processable in cases such as failure in securing memory. You can determine whether an Explicit memory block is processable.
- Used API
-
isActive()
The following table describes the mapping of the status of the Explicit memory block (ExplicitMemory instance), when the API is invoked, and the return value of the API.
|
Status of Explicit memory block |
Sub-status |
Return value |
|---|---|---|
|
Released |
-- |
false |
|
Invalid |
-- |
false |
|
Reserved for releasing |
-- |
false |
|
Valid |
Enable |
true |
|
Disable |
false |
- Legend:
-
--: Not applicable
(6) Determining whether the Explicit memory block can be reserved for release
You can refer to the ExplicitMemory instance corresponding to an Explicit memory block even after the Explicit memory block is reserved for releasing or released. You can check the status of the Explicit memory instance from an application by using the API.
- Used API
-
isReclaimed()
The following table describes the mapping of the status of the Explicit memory block (ExplicitMemory instance), when the API is invoked, and the return value of the API.
|
Status of Explicit memory block |
Sub-status |
Return value |
|---|---|---|
|
Released |
-- |
true |
|
Invalid |
-- |
true |
|
Reserved for releasing |
-- |
true |
|
Valid |
Enable |
false |
|
Disable |
false |
- Legend:
-
--: Not applicable