I create the autorun cd of which contains the dicom images.
it taks arround 10-15 min. to display dicomviewer on screen.
so, I want to increase the jvm heap size at runtime, programatically,(not from the commandline)
suppose i have to allocate 500mb to my app when i start the app.
is it possible?
i am using windows platform.
Literally, no. The max heap size is set at JVM launch time and cannot be increased.
In practice, you could just set the max heap size to as large as your platform will allow, and let the JVM grow the heap as it needs. There is an obvious risk in doing this; i.e. that your application will use all of the memory and cause the user's machine to grind to a halt. But that risk is implicit in your question.
One approach you can take in a Windows environment is to install a service that starts up your application. Via this method you can make the windows service point to a wrapper file that calls all the relvant files to start up your application. Here you can specify something like;
set JAVA_OPTS=-Xrs -Xms6G -Xmx6G -XX:MaxPermSize=384M
You can use this to specify your JVM memory settings on startup.
Please see http://docs.oracle.com/cd/E19900-01/819-4742/abeik/index.html for more information about the parameters.
Hope this helps,
V
Since the problem is about the duration of the pictures display and knowing that you cannot change the heap size programmatically, what about optimizing your program to load the pictures faster ?
You can use multiple threads or asynchronous loading to speedup the display.
You may also use paging in the user interface.
Can you edit the code of the user interface ?
Related
Many times my java process is crashing with Java Cores and Heap Dumps.
When that happens, the resulting core files fill up my File System.
So, we need to periodically remove them to not fill up the File system.
Is there any way of limiting the size of heap or javacore?
More importantly, is there a way to make sure previous java core is overwritten by another core file Like a rollover mechanism(log4j) for Java process cores?
Thanks,
Sashi
If -XX:+HeapDumpOnOutOfMemoryError is present in your application, the heap dump is getting generated because your application is asking it to get generated on OOM. If you don't want that, remove the argument. But, that will not fix your actual problem for sure.
MY GOAL:
I want run my application for 1000 users.
NOW
I am trying to run for 100 user. During application run, I'd like to do some process for each user that will take a minimum of one hour per user, so I'm using one thread per user.
ERROR
Caused by: java.lang.OutOfMemoryError: Java heap space
I've tried to figure out what this means, but I'm not really sure how to resolve it.
Can anybody help me?
This error means that your program needs more memory than your JVM allowed it to use!
Therefore you pretty much have two options:
Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m)
Modify your program so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program
As Peter Lawrey pointed out, using a profiler to see what your program is doing in such situations is generally a good idea.
Use a producer/consumer pattern with a limited number of worker threads.
100+ threads is ridiculous - no wonder your application is exploding.
You haven't provided any information which indicates the problem is very different to all the answers given in StackOverflow regarding this error either;
You are using too much memory and you need to use a memory profiler to reduce it.
You are setting the maximum memory too low and you need to increase the maximum memory with -mx or -Xmx
I suspect that since you want 1000 users to run processes which take an hour each you may need more resources than you have. e.g. 1000 cores perhaps? I suggest you look at how much hardware you need based on the CPU, memory, disk IO and network IO that is required to run the users at an acceptible level e.g. 20 users and multiple that by 50.
You can try increasing the JVM heap space when you launch your application. You can try setting it to 2GB with -Xmx2g. If you're running 32-bit Java I think 2GB is as high as you can go, but if you have a 64-bit JVM you should be able to go higher.
Edit:
Example: java -Xmx2g MyApp
I will check 2 areas when there is out of memory error
Is the allocated memory to the JVM sufficient, if not increase it using -Xmx
Check the code thoroughly, more than 90% of the time I found the error with some loop going recursive under some border condition.
I am shipping an Eclipse based application and want to have maximum Heap size. How can I make my application use all avilable memory on different machines. All I have found so far is the paramaters for setting heapsize that I can send the JVM but these are hardcoded. Basically I want the JVM to use whatever memory is available on the machine. Hard coding is not good enough.
Is there an easy way of doing this?
Not possible using standard JVM features. JVM parameters specify the amount of memory to reserve (-Xmx...), not possible to specify "take all memory available". You could try a reasonable value like 1.2GB, that is the upper limit in Windows XP 32bit, for example. The problem is that the OS could not reserve all memory required by JVM so you must be more conservative.
The other approach is to calculate the available memory externally (script, native utility) and then set the JVM parameter with that value. NOt know if any installer like Install4J could achieve this.
i have developed chatting application using threads. but when i start my application system acts very slow and sometime exception occur that heap is full. i want to increase heap size of Java Virtual Machine. how can i do it?
Just increase the heap size of the JVM. All Java applications, even simple ones, consume a lot of memory. Take a look at this article explaining in detail how to increase the amount of memory available for your application; basically you'll need to pass a couple of extra parameters to the JVM when you invoke the java command, like this:
java -Xms64m -Xmx256m HelloWorld
In the above command, I'm saying that the HelloWorld program should have an initial heap size of 64MB and a maximum of 256MB. Try with these values and fiddle a bit with them until you find a combination of values that works for your application.
You can increase heap size, but your larger issue is "Why did I get that exception?" Increasing the heap size will only delay the inevitable if your application is not cleaning up after itself properly.
You need to instrument your application with Visual VM and see what's going on. That will give you more of a path forward than simply increasing the heap size.
Add -Xmx100m to the command when you start your app. This will give you 100 MB heap (you can change the number).
It sounds strange that a chat app would required more than the standard heap size...
Blockquote
Large server applications often experience two problems with these
defaults. One is slow startup, because the initial heap is small and
must be resized over many major collections. A more pressing problem
is that the default maximum heap size is unreasonably small for most
server applications.
Blockquote
You could start your program via command prompt with these parameters
java -Xms64m -Xmx256m chat_program.
Here Xms64m = 64mb initial heap size
and Xmx256m = 256mb maximum heap size
I have one main class that contains 5 buttons each link to a program/package. Each package runs a jmf program that capture images from a webcam and it also loads about 15 images from file.
The 1st program to load(regardless of which button i press) always runs correctly. But When i run a program after the 1st program ends, java.lang.OutOfMemoryError: java heap space occurs.
Im not sure if java can't handle all of our images or if it has something to do with jmf image capture.
Maybe you should give more memory to your JVM (-Xmx512m on the command line could be a good start),
then, if it solves the problem, investigate why your programs consumes so much memory.
The use of sun diagnostic tools like jvisualvm could be helpful.
Increase the Java maximum memory and re-rerun. If you still see OOM's, you may have a leak. To increase the max memory, append -Xmx<new heap size>m to your command line.
Example:
java -Xmx1024m Foo
How much memory are you giving to your JVM? You can give it more using the following: -Xmx1024m (for 1GB, adjust as necessary)
This assumes that you don't have some memory leak in your program. I don't know anything about JMF, this is just general advice for Out of Memory errors.
JVMs run with a limited amount of maximum memory available to them. This is a little counterintuitive and trips a lot of people up (I can't think of many similar environments).
You can increase the max memory the JVM takes by specifying
java -Xmx128m ...
or similar. If you know in advance that you're going to consume that amount of memory, use
java -Xms128m ...
to specify the memory that the JVM will allocate at startup. Note the -Xms vs -Xmx !
Try to check, if you still have some references around which prevent the first package/program to be garbage-collected.
When the launcher has detected that the first program has ended, set all references to the first program and maybe objects retrieved from it to NULL to allow the JVM to reclaim the memory again and have it ready for the second launch.
Java uses 64 MByte heap space by default. An alternative to the other suggestions (increasing heap space to 512M or 1024M) is to start separate JVMs for the controller and the 5 applications. Then if one of your JMF applications crashes (due to insufficient memory), the controller and the other apps are still running.
(this will only work if the applications and the controller are completely decoupled - otherwise, just increase the heap size and dispose all media as soon as you don't need it anymore to prevent from memory leaks)