Hello dear fellow developers,
I am facing issue with heap memory usage in my java application. Application itself is simply accepts Socket connections
Main Thread I have following script nothing more (except static ExecutorService instance):
ServerSocketFactory serverFactory = ServerSocketFactory.getDefault();
ServerSocket server = serverFactory.createServerSocket(Configuration.port);
for(;;)
{
Socket client = server.accept();
Configuration.getExecutor().submit(new Client(client));
}
When Application is running, it should block loop until someone gets connected... Which means my Main thread is on waiting state most of the time...
The problem is: When no one is connected to my Server, Heap memory usage is fluctuating (see screenshot below) Which means there is a memory leak? no? Or it is the natural way how java application behaves?
Thanks in advance...
Your memory usage is fluctuating between 0 and 20MB and not increasing. There is neither a memory leak or any reason why you should pay any attention to this.
It looks like something is getting garbage collected. Remember that on a computer with realistic amounts of main memory, that slope will appear a thousand times smaller. I don't think it's worth worrying about.
If you are using visualvm
or jconsole
or jmc
to monitor heap usage it uses RMI and JMX which creates quite a lot of garbage. ie it is your monitoring which is doing this.
BTW even if you have a simple program
System.in.read();
these tools will show that garbage is being created, but not by your program.
I suggest you try instead use
jps -lvm
to get the process id or pid
jstat -gccause {pid} 10s
to monitor the memory usage. This also creates a small amount of garbage much far less.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.