I have a process that collect data object from database (hibernate+oracle) and save them to another database the amount of data object near 10,000.
This takes 1000+ Runtime memory. And this memory doesn't reduced after finished the process.
The memory status and the Thread status printed after finished below...
Runtime runtime = Runtime.getRuntime();
total = runtime.totalMemory() / MB;
free = runtime.freeMemory() / MB;
used = total - free;
max = runtime.maxMemory();
System.out.println("Memory Status >>> [ Used: " + used + " MB, Free: " + free + " MB, Total: "+total+" MB ]");
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (Thread t : threadSet) {
System.out.println(t.getState() +" ("+ t.isAlive() + ") : " +t.getName()+" || " +Thread.currentThread().getName() );
}
The output
Memory Status >>> [ Used: 1262 MB, Free: 719 MB, Total: 1981 MB ]
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : http-bio-8123-exec-1
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : http-bio-8123-exec-16
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : http-bio-8123-exec-11
WAITING (true) : Finalizer
RUNNABLE (true) : main
WAITING (true) : Java2D Disposer
RUNNABLE (true) : http-bio-8123-Acceptor-0
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : http-bio-8123-exec-4
RUNNABLE (true) : http-bio-8123-exec-2
RUNNABLE (true) : ajp-bio-8009-Acceptor-0
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : Reference Handler
WAITING (true) : http-bio-8123-exec-17
TIMED_WAITING (true) : ajp-bio-8009-AsyncTimeout
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
TIMED_WAITING (true) : ContainerBackgroundProcessor[StandardEngine[Catalina]]
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : File Reaper
WAITING (true) : http-bio-8123-exec-10
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
WAITING (true) : http-bio-8123-exec-20
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
TIMED_WAITING (true) : GC Daemon
WAITING (true) : http-bio-8123-exec-12
TIMED_WAITING (true) : http-bio-8123-AsyncTimeout
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
RUNNABLE (true) : Signal Dispatcher
WAITING (true) : http-bio-8123-exec-19
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
TIMED_WAITING (true) : Timer-0
RUNNABLE (true) : Memcached IO over {MemcachedConnection to /192.168.39.205:11211}
How can I reduce USED memory, And how can I find out, who use this big memory ?