Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35262

Restricting the memory usage of a Java program

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.programmer
Subject Restricting the memory usage of a Java program
Date 2016-08-11 23:42 +0200
Organization Decebal Computing
Message-ID <8760r7m18z.fsf@Equus.decebal.nl> (permalink)

Show all headers | View raw


I made a little program for cropping images. When just starting it as
a Java program the memory usage was just way to much. So I wrote the
following script:
#!/usr/bin/env bash

declare -r CLASS=CropImage
declare -r MIN_MEM=128M
declare -r MAX_MEM=256M

# Make sure you are in the right directory.
# Only start the Java application when moving to the right directory was succesful.
cd "${0%/*}" && java "-Xms${MIN_MEM}" "-Xmx${MAX_MEM}" "${CLASS}" &

And now the memory consumption is much less and as far as I can see
without negative consequences for the program.

The values I use (128 MB and 256 MB) are just values I kind of
randomly choose. Is there a way to find ‘optimal’ values?


Bonus question: is there a way to limit the memory usage when the
program is started with:
    java CropImage
instead of the script?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Restricting the memory usage of a Java program Cecil Westerhof <Cecil@decebal.nl> - 2016-08-11 23:42 +0200
  Re: Restricting the memory usage of a Java program Arne Vajhøj <arne@vajhoej.dk> - 2016-08-11 18:04 -0400
    Re: Restricting the memory usage of a Java program Cecil Westerhof <Cecil@decebal.nl> - 2016-08-12 10:34 +0200
      Re: Restricting the memory usage of a Java program Martin Gregorie <martin@address-in-sig.invalid> - 2016-08-12 10:08 +0000
      Re: Restricting the memory usage of a Java program Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 09:23 -0400
        Re: Restricting the memory usage of a Java program Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 01:11 +0200
          Re: Restricting the memory usage of a Java program Cecil Westerhof <Cecil@decebal.nl> - 2016-08-13 02:52 +0200
          Re: Restricting the memory usage of a Java program Arne Vajhøj <arne@vajhoej.dk> - 2016-08-12 21:05 -0400
  Re: Restricting the memory usage of a Java program Arne Vajhøj <arne@vajhoej.dk> - 2016-08-11 18:24 -0400

csiph-web