Skip to content
Advertisement

Linux java, max disk space size of file

I want to ask, if:

-Xms1000M -Xmx1000M

Are commands for Java (Linux) for maximum file usage of RAM, is there opinion to do same with Disc space?

Example to set max file size at running it, same as for RAM, just for HDD/SSD space.

Thanks to all in advance.

Advertisement

Answer

First of all, the -Xms1000M and -Xmx1000M do not set a limit on the JVM’s usage of RAM. They set the initial size and limit for the Java heap … where regular objects are held. A JVM uses RAM for many other things that are not regular objects; e.g. stacks, metaspace, space used by the executable and various kinds of off-heap allocations, and so on. These are not limited by -Xms and -Xmx.

To answer your actual question: Java does not provide a way to limit the amount of disk space consumed by a program.

On Linux / UNIX you can limit the size of files written via the shell builtin command ulimit. (The limit that controls this is the -s limit.) However, since this is a builtin command that limits the current shell and its child process, using Process to run bash -c ulimit is not going to be effective. The command must be run before you launch the JVM.

To answer the question that you might have been trying to ask: Java doesn’t provide a way to limit the total RAM used either. But you can do this with ulimit; see above.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement