0

I am trying to execute this program using fork and join framework. When I feed a JPEG image of smaller size to this program it works fine, but when I give the image of size more than 4 MB it throws below exception:

****Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at ForkBlur.blur(ForkBlur.java:120)
    at ForkBlur.main(ForkBlur.java:110)****

I am using eclipse Helios IDE.

I want it to work for larger images of size more than 50 MB

Voila
  • 306
  • 2
  • 5
  • 16

3 Answers3

7

It worked fine for me .

Right click on project which you want to run . Run As -> Run configuration ->Arguments .

Then in VM arguments:

-Xmx1g

Voila
  • 306
  • 2
  • 5
  • 16
2

You need to specify a bigger heap size when you run the program.

You can do it via eclipse if that's your preferred tool. You can right click on the file containing the main method, choose the option "Run As" - this would open up a dialog where you can set up host of command line options (look for arguments section).

The command line option to configure the maximum heap size is Xmx; an example would be Xmx 2g to set the maximum heap size to 2 gb.

Scorpion
  • 3,938
  • 24
  • 37
2

You'll need to tell the JVM to allow for more memory for your program. If running the program from the command line, you would use the -mx option to specify how much memory the JVM is allowed to use.

For example, to allow for 128MB of memory, you would do:

java -mx128M MyClass

If running from Eclipse Helios, do this:

  1. Right click on the project and go to properties.
  2. Click on Run/Debug Settings.
  3. Choose your run configuration and click Edit or click New to create one using the Java Application configuration type.
  4. On the Arguments tab, put -mx128M in the VM arguments box.
Eric Petroelje
  • 59,820
  • 9
  • 127
  • 177
  • AFAIK, it is Xmx, the command line option, mx is probably a typo? – Scorpion Jan 17 '13 at 18:08
  • 1
    @Scorpion - The `mx` option is now a standard java option and doesn't require the leading `X` anymore. Although `-Xmx` will still work, and may be required if you are using an older version of Java. – Eric Petroelje Jan 17 '13 at 18:09