Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: How to allow Java to use more memory on Linux.

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to allow Java to use more memory on Linux.

    Hello, I'm trying to allow a java .jar file to use the 2gb's of memory available on my linux computer. However, I get an allocation error when using over 1024mb's on Xmx or Xms. How do I allow the system to give java the memory it needs.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: How to allow Java to use more memory on Linux.

    an allocation error
    Always copy-paste error messages. Perhaps you don't have as much memory spare as you're trying to give to Java? Are you running more than one instance of your program?

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    I can't paste the message as it just shuts down after loading everything. But the message is, from what I can see. "Error can't allocate memory to java".

    My system has 2.5gb's of memory, but when I set -Xmx -Xms higher then 1024mb's it gives me this error. I googled this and a few people said the system was blocking it from be able to allow more then 1024mb's.

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: How to allow Java to use more memory on Linux.

    If your system can't allocate memory, it doesn't have it to spare. What command line are you using? For example this doesn't work on my PC:
    java -Xms22G -version
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    but it will run like this
    java -Xms20G -version
    java version "1.6.0_24"
    OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu2)
    OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
    It's not always obvious how much of your PC's memory is 'spare' - try to find out what value for Xms (on your system, something like Xms800M might be a good one to try) the problem starts at, let us have the output from -version, and some clue from your OS how much memory you have and how much is spare. I use 'top' to get summary memory stats on Ubuntu.

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    Running "top" on my linux I see that I have:

    Mem: 2621440k total, 1698936k used, 922504k free,

    When Java is running with it's 1024M limit. Any number higher just gives me allocation errors.

  6. #6
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: How to allow Java to use more memory on Linux.

    and the output of "java -version"? Are you sure you're stopping the previous one before running the next one? You should have nearly 2G free before starting java

  7. #7
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    I checked the running processes and nothing for Java was running, still when I start it I get the error Can't Allocate Memory for any value higher then 1024MB.

  8. #8
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: How to allow Java to use more memory on Linux.

    what is the output of "java -version"?

    You can post the output of uname -a too, if you like. And confirm for us that this is a physical machine and not a virtual one.

  9. #9
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: How to allow Java to use more memory on Linux.

    You're running a 32 bit JVM and/or you're environment limits you. A "ulimit -v" shows how much virtual memory (from an O/S level) your process is allowed to use. And I've never heard of a machine with 2.5 gig of memory but I guess it is possible.

    A 32 bit JVM will likely top out at around 1.5 gig with a freshly rebooted system. A system that has been running a while might be less.

    As Sean4u asked, we need a "java -version", a "uname -a" and I'd like the "ulimit -v". I'm a bit concerned that you can't grab an error message because it implies that you're not comfortable using a command line.
    Need Java help? Check out the HotJoe Java Help forums!

  10. #10
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    Let me clear a few things up here, as I feel I've been a little misleading. First, my linux system is a virtual private server. Second, I'm running 32bit Ubuntu. Third, here is the information you wanted.

    java version "1.6.0_22"
    OpenJDK Runtime Environment (IcedTea6 1.10.6) (6b22-1.10.6-0ubuntu1)
    OpenJDK Server VM (build 20.0-b11, mixed mode)

    Linux server1 2.6.18-274.el5.028stab093.2 #1 SMP Tue Aug 23 16:46:17 MSD 2011 i686 athlon i386 GNU/Linux

    unlimited

    I hope this helps, and yes I have contacted my server provider about this and they are taking all month to get back to me. I thought it might be something Java could fix.

  11. #11
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: How to allow Java to use more memory on Linux.

    I'm personally not a big fan of OpenJDK though, I'll be honest, it's more because of my (depressingly long) history with the Sun/Oracle JDK than any true issues. 1.0 beta - that was my first experience...

    Anyhow, you're a bit stuck with the environment you have. But I suppose the real question we all should have been asking is why does your app need 2GB of memory? There are plenty of valid reasons for using that much memory but there are likely more invalid reasons. What data/code/etc. is it caching that requires that kind of memory? I run production Glassfish servers supporting hundreds of simultaneous users on an Amazon instance. I allocate a total of 2GB for that and have never come close to running out of memory.

    Can you describe your application a bit? Perhaps there are other paths.
    Need Java help? Check out the HotJoe Java Help forums!

  12. #12
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    My application is a game server, to be specific a minecraft server. It needs this memory because everything runs off memory when you open it, if you have around 30 people playing at one time you can run out of memory very fast.

  13. #13
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: How to allow Java to use more memory on Linux.

    Ok, makes sense - look to upgrade your server a bit. I'm not familiar with OpenJDK limitations but even the real JDK will not get you too far past the 1GB mark.
    Need Java help? Check out the HotJoe Java Help forums!

  14. #14
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    Reinstalling the operating system to Debian 6 64bit and "sun-java6-jdk" fixed the memory problem. Guess it was the 32bit operating system.

  15. #15
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How to allow Java to use more memory on Linux.

    you was try linux red hat?

Similar Threads

  1. Replies: 1
    Last Post: June 7th, 2011, 11:53 AM
  2. How to set java compiler compliance with command under Linux
    By Eric97 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 9th, 2010, 09:25 AM
  3. Memory Handling -de allocate memory in Java
    By 19world in forum Java Theory & Questions
    Replies: 4
    Last Post: June 15th, 2010, 04:05 AM
  4. miniBuilder on Linux- java errors
    By nwtjv in forum Exceptions
    Replies: 0
    Last Post: March 25th, 2010, 06:54 AM
  5. Executing Linux Commands with Java GUI
    By linuxrockers in forum AWT / Java Swing
    Replies: 2
    Last Post: February 15th, 2010, 10:57 PM