Java.lang.OutOfMemoryError: Java heap space in Maven?

Setting the Xmx options using MAVEN_OPTS does work, it does configure the JVM used to start Maven. That being said, the maven-surefire-plugin forks a new JVM by default, and your MAVEN_OPTS are thus not passed.

When I run maven test, java.lang. OutOfMemoryError happens. I google it for solutions and have tried to export MAVEN_OPTS=-Xmx1024m, but it did not work.

Setting the Xmx options using MAVEN_OPTS does work, it does configure the JVM used to start Maven. That being said, the maven-surefire-plugin forks a new JVM by default, and your MAVEN_OPTS are thus not passed. To configure the sizing of the JVM used by the maven-surefire-plugin, you would either have to: change the forkMode to never (which is be a not so good idea because Maven won't be isolated from the test) ~or~ use the argLine parameter (the right way): In the later case, something like this: -Xmx1024m But I have to say that I tend to agree with Stephen here, there is very likely something wrong with one of your test and I'm not sure that giving more memory is the right solution to "solve" (hide?) your problem.

References Maven 2 Surefire Plugin Classloading and Forking in Maven Surefire.

The chances are that the problem is in one of the unit tests that you've asked Maven to run. As such fiddling with the heap size is the wrong approach. Instead, you should be looking at the unit test that has caused the OOME, and trying to figure out if it is the fault of the unit test or the code that it is testing.

Start by looking at the stack trace. If there isn't one, run mvn ... test again with the -e option.

Stephen,I can pass the test case in eclipse after I set-Xmx1024m in run configuration, but it always throw OutOfMemoryError when I run "mvn test" in console, even when I add -e options "mvn test -DMAVEN_OPTS=-Xmx1024m" – zjffdu Nov 1 '10 at 4:32 @zjffdu - You completely missed my point! The purpose of adding "-e" is not to make the tests work. It is to find out why they don't work.

– Stephen C Nov 1 '10 at 4:49 @Stephen, I add the 'e' option, but did not get enough useful information. – zjffdu Nov 1 '10 at 8:40 @zjffdu - it says "Please refer to E:\Code\Java\workspace\dw. Pig\target\surefire-reports for the individual test results".

Did you? – Stephen C Nov 1 '10 at 10:47 @Stephen,Yes I look at that, no useful information. – zjffdu Nov 1 '10 at 12:54.

Is there a way to allow you to create and store Double. MAX_VALUE objects in a Collection? No.

There's not that much RAM on Earth Double. MAX_VALUE is about 2 times ten to the 308th power: that's 2 followed by over 300 zeros. Give Best Buy a call, see how much they'd charge to put that in your computer.

Is there a way to allow you to create and store Double. MAX_VALUE objects in a Collection? No.

There's not that much RAM on Earth. Double. MAX_VALUE is about 2 times ten to the 308th power: that's 2 followed by over 300 zeros.

Give Best Buy a call, see how much they'd charge to put that in your computer.

– OpenMind Aug 10 at 15:27 5 @OpenMind: The solution is not to attempt the impossible. – Michael Borgwardt Aug 10 at 15:29 1 There is no solution. You cant store that much!

– Paranaix Aug 10 at 15:29 3 Chuck Norris can do it! – Hovercraft Full Of Eels Aug 10 at 15:32 1 Write a better algorithm, just store the already selected numbers and do a random again if you've got the same and you don't have enough. – KARASZI István Aug 10 at 15:34.

Even if you had enough memory, ArrayList can have at most Integer. MAX_VALUE elements. Double.

MAX_VALUE far exceeds said limit. In this case, you ran out of memory during an add that caused the array list to grow.

" (I just want to see a big number ^^) – pst Aug 10 at 15:28.

Yet another reason why your code cannot work: double can only represent integers exactly up to about 2^52 - after that, i++ will have no effect and the for loop will never terminate. You should never use floating-point variables as loop counters. Use int or long instead.

1 Although I think there might already be problems if code tries to loop 2^52 times... ;-) – pst Aug 10 at 15:34 Well, it'll give him slightly unexpected results, at least. That, and because he actually tests I At some point, I == i+1 – Michael Borgwardt Aug 10 at 18:26 #winces# I didn't realize the imprecision got that bad, even in the upper range... Oh, grr, it would have to increment in a (positive non-zero) power of ten after that, wouldn't it... – X-Zero Aug 10 at 18:42 @X-Zero: power of two, actually. And it's not that the imprecision gets worse - it's always the same, relative to the magnitude of the number being represented.

Once you're up to 2^52, an increase of 1 is (justly) assumed not to matter much. OTOH, the format can distinguish between 0.00000000000001 and 0.00000000000002 - Any attempt to represent an uncountably infinite set in will require some tradeoffs, and it's really quite marvelous how it can be done in only 64 bits and work quite well most of the time. – Michael Borgwardt Aug 10 at 19:19.

You are trying to allocate of the order of 10^308 values. That's a lot of values.

10^308 just looks small ;p – pst Aug 10 at 15:29 2 @pst 10000000000000000000000000000000000000000000000000000000000000000000000000000000?000000000000000000000000000000000000000000000000000000000000000000000000000000000?000000000000000000000000000000000000000000000000000000000000000000000000000000000?0000000000000000000000000000000000000000000000000000000000000000000. Yup, still looks small... – Paul Cager Aug 10 at 16:07 Nicely done ;-) – pst Aug 10 at 20:55.

Instead of doing what you are currently doing, you should just obtain 10 random doubles, add them to an ArrayList and sort it. That is basically what your method is doing. To obtain a random double, look at Random.nextDouble().

(A PC still won't come close. ) – pst Aug 10 at 15:30 1 That's better, although you probably still don't have that much memory. That's about 2 billion objects, at least 12 bytes each, plus the array in the array list; so 24GB for the objects and another 8B for the array.

– Ernest Friedman-ll Aug 10 at 15:32 1 @Ernest: well, it's not completely impossible for a consumer-grade PC to have 24GB of RAM; in fact, in 5 years' time it will probably be normal. – Michael Borgwardt Aug 10 at 15:34 Indeed, that's why I said "you probably still don't have that much". I have a server that does, but none of my desktops do!

– Ernest Friedman-.

In you loop: for (double I = 1; I If not it will increase the size of the ArrayList and then continue adding. So what you are basically doing is using all the memory allocated in your heap when you are creating this ArrayList. If you make your ArrayList smaller you should be able to hold it in memory.

Increasing the size of the heap will do. Just run the program with this argument: -Xmx512m It will increase your heap size to 512 MB. You can specify as much as you want: 1g, 2g and so on.

2 Would require -XmxIMPOSSIBLENUMBER in this case... – pst Aug 10 at 15:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions