The behavior your describe is normal for Java applications.
What are your -Xms and -Xmx values? They set the minimum and maximum allocation pools for heap memory.
In general it is recommended for production environments (i.e. environments that are used by the public) to have the same values for -Xms and -Xmx. Java will fluxuate the heap memory between those two memory sizes. If the heap minimum memory size (-Xms) is below -Xmx and it needs to allocate more from the system then it will take extra time to allocate that memory for the heap. Because of that it is recommended to give the heap a fixed size by setting -Xms and -Xmx the same value.
For instance on the
minecraft website they recommend starting the JVM with the following options for the dedicated server...
Code:
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Just remember that your java application is actually a JVM (Java Virtual Machine). You can think of it like any other virtual machine where it emulates its own instruction set architecture and manages its own memory (in this case through garbage collection).
I'd also like to point out that Java has more types of memory than just the heap. Look up on google for
types of java memory. That being said since there are other types of memory in Java than just the heap it is possible for your JVM to go above the maximum pool size set by -Xmx. You can control the sizes other types of Java memory by passing additional options but I don't need to get into that. For minecraft, the default sizes for other types of memory are fine and usually only adjusted to tune garbage collection.
If you would like a true representation of how your JVM is managing memory then you must connect
jconsole to your JVM. The OS won't report true memory usage within the JVM otherwise.