Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35262
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Restricting the memory usage of a Java program |
| Date | Thu, 11 Aug 2016 23:42:04 +0200 |
| Organization | Decebal Computing |
| Lines | 29 |
| Message-ID | <8760r7m18z.fsf@Equus.decebal.nl> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="31566"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HdKm257rtdP/ITG1/ODfoWxEaYBdI8Vs=" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| X-Homepage | http://www.decebal.nl/ |
| Cancel-Lock | sha1:j8d7vbbLDj4TiEmmn/oe6+8/Opk= sha1:3/xnMLiIoifaeBiVHJ8gLi/bbZ8= |
| Xref | csiph.com comp.lang.java.programmer:35262 |
Show key headers only | 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
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