Search code examples
javaweb-applicationsvirtual-memoryswapfile

How to use virtual memory (swap in linux file system ) in java web programming


I work in java web application . In some section i use very huge tree variable that save and persist in memory (RAM) . Can i migrate this to virtual memory (swap) . note : huge tree consist name and email for all user that use in suggestion Ajax text-box .


Solution

  • There isn't a standard way in Linux of forcing a block of memory to swap, thus the JVM will not have a way of asking the OS to perform such a task.

    The best you can do if you want this functionality, is to serialize the tree and write the raw data to a disk file then bring it back when you're ready for it.

    But you probably don't want this, because writing to a disk is extremely slow when compared to physical memory i/o.

    Case in point, let the OS worry about this. It's safe to assume it knows a better way of managing memory than you do.