Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35263
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Restricting the memory usage of a Java program |
| Date | Thu, 11 Aug 2016 18:04:16 -0400 |
| Organization | Aioe.org NNTP Server |
| Lines | 29 |
| Message-ID | <noisp2$12e7$1@gioia.aioe.org> (permalink) |
| References | <8760r7m18z.fsf@Equus.decebal.nl> |
| NNTP-Posting-Host | 7SK6yTFfqwlIPNBLl3l7Qg.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.java.programmer:35263 |
Show key headers only | View raw
On 8/11/2016 5:42 PM, Cecil Westerhof wrote:
> 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?
System.gc();
Runtime rt = Runtime.getRuntime();
long actual_value = rt.totalMemory() - rt.freeMemory();
long good_value = SOME_MAGIC_FACTOR * actual_value;
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | 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