Setting heap size

I hope you will all forgive me because this has been exhausted although I followed all the advices.
After the following examples, to check my own environment. I have done the following:
long heapSize = Runtime.getRuntime().totalMemory();
    System.out.println(heapSize);
    // Get maximum size of heap in bytes. The heap cannot grow beyond this size.
    // Any attempt will result in an OutOfMemoryException.
    long heapMaxSize = Runtime.getRuntime().maxMemory();
    System.out.println(heapMaxSize);
    // Get amount of free memory within the heap in bytes. This size will increase
    // after garbage collection and decrease as new objects are created.
    long heapFreeSize = Runtime.getRuntime().freeMemory();
    System.out.println(heapFreeSize);
        Which outputs is:
5177344
66650112
4437824
Currently, it looks like my heap cannot grow more than 6.6M right?
Now if I want to increase my maximum heap size, the command is adviced to be:
java -Xmx128m readFile.class
However, it keeps coming oout with an error:
Exception in thread "main" java.lang.NoClassDefFoundError: readFile/class
Where did that "main" come from? The only thing that I have done is that I have another class called myMain which calls this clss for test purposes.
The class which raised this heap problem was a class I was using to read files as in the bellow:
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class readFile
private ArrayList<String>  dataFromFile= new ArrayList<String>();
    public String readFile(String fileNameIn, String encoding) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(
      new FileInputStream(fileNameIn), encoding));
      buffer = new StringBuffer();
    int i;
    while((i = in.read()) != -1) buffer.append((char)i);
    in.close();
    return buffer.toString();
//return an array of each data read from file separated by a tab etc
  public ArrayList<String> getRecords(String fileNameIn) throws IOException {
      String  s = this.readFile(fileNameIn);
      String current;
      Pattern p = Pattern.compile("[^\t\n]+|\t(?=\t)|\t$",
      Pattern.CASE_INSENSITIVE);
      Matcher m = p.matcher(s);
      while(m.find()){
         current = m.group(0).trim();
         dataFromFile.add(current);
        }//while 
    return dataFromFile;
}Message was edited by:
McTaar
Message was edited by:
McTaar

This is the error displayed:
java.lang.OutOfMemoryError: Java heap space
     at java.util.Arrays.copyOf(Arrays.java:2760)
     at java.util.Arrays.copyOf(Arrays.java:2734)
     at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
     at java.util.ArrayList.add(ArrayList.java:351)
     at readFile.getRecords(readFile.java:41)
     at myMain.main(myMain.java:79)readFile: 41 is
dataFromFile.add(current);

Similar Messages

  • Benefit of setting heap size

    Hello sir,
    what is the benefit of setting heap size in java....?
    java -Xms40m -Xmx80m <program name>

    benefit of setting heap sizeIt is not for the benefit! It is for the need!!
    If you are encountering java.lang.OutOfMemoryError, then you can avoid this error, by setting heap size as reasonable.

  • Mapping set heap sizes to used memory

    Hi all,
    I've got a question about the parameters used to control your java process' heap sizes: "-Xms128m -Xmx256m" etc.
    Let's say I set my min and max to 2Gb, just for a simplistic example.
    If I then look at the linux server my process is running on, I may see a top screen like so:
    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    10647 javaprog 20   0 2180m 1.9g  18m S  1.3  3.7   1:57.02 javaWhat I'm trying to understand is what relationship - if any - there is between these arguments and the figures I see within top. One thing in particular that I'm interested in is the fact that I occasionally see a RES (or more commonly a VIRT) size higher than the maximum that I have provided to Java. Naively I would assume that therefore there isn't a relationship between the two... but I wouldn't mind someone clarifiying this for me.
    Any resources on the matter would be appreciated, and I apologise if this question is outside the realms of this particular subforum.
    Dave.

    Peter Lawrey wrote:
    user5287726 wrote:
    Peter Lawrey wrote:
    It will always reserve this much virtual memory, plus. In term of resident memory, even the minimum is not guarenteed to be used. The minimum specifies at what point it will make little effort to recycle memory. i.e. it grows to the minimum size freely, but a "Hello World" program still won't use the minimum size.No, Linux does not reserve virtual memory. Just Google "Linux memory overcommit". Out-of-the-box, every Linux distro I'm aware of will just keep returning virtual memory to processes until things fall apart and the kernel starts killing processes that are using lots of memory - like your database server, web server, or application-critical JVMs. You know - the very processes you built and deployed the machine to run. Just Google "Linux OOM killer".Thats not the behaviour I see. When I start a process which busy waits, but doesn't create any objects, the virtual memory sized used is based on the -mx option, not how much is used. Given virtual memeory is largely free, why would an OS only give virtual memory on an as needs basis.
    Busy looping process which does nothing.
    In each case the resident size is 16m
    option       virtual size
    -mx100m      368m = 100m + 268m
    -mx250m      517m = 250m + 267m
    -mx500m      769m = 500m + 269m
    -mx1g        1294m = 1024m + 270m
    -mx2g        2321m = 2048m + 273mTo me it appears that the maximum size you ask is immediately added to the virtual memory size, even if its not used (plus an overhead) i.e. the resident size is only 16m.Yes, it's only using 16m. And its virtual size may very well be what you see. But that doesn't mean the OS actually has enough RAM + swap the hold what it tells all running processes they can have.
    How much RAM + swap does your machine have? Say it's 4 GB. You can probably run 10 or 20 JVMs simultaneously with the "-mx2g" option. Imagine what happens, though, if they actually try and use that memory - that the OS said they could have, but which doesn't all exist.
    What happens?
    The OOM killer fires up and starts killing processes. Which ones? Gee, it's a "standard election procedure". Which on a server that's actually doing something tend to be the processes actually doing something, like your DBMS or web server or JVM. Or maybe it's your backups that get whacked because they're "newly started" and got promised access to memory that doesn't exist.
    Memory overcommit on a server with availability and reliability requirements more stringent than risible is indefensible.

  • Unable to set heap size to 4gb in sun java application server pe 8.2

    i have sun v890 machine with 32gb ram and solaris 10
    i am running sun java system application server platform edition 8.2
    when i am setting max heap size to 4GB
    it is giving an error
    Invalid maximum heap size -Xmx4096m
    the specified size exceeds the maximum representable size
    i want to know what i should do to increase this heap size.
    also tell me if the JVM running is 64bit. if not how can i change it
    to 64bit VM.

    The maximum size for a 32-bit process on Solaris (any 32-bit process, not just Java) is 4GB, which includes the program text, thread stacks, and various other things in addition to the JVM heap. So the maximum heap you can expect to allocate for the appserver is about 3500MB.
    SJSAS 8.2 does not support a 64-bit JVM; SJSAS 9.1 is needed for that. However, it's very rare that a Java EE application actually needs that much memory, and the 64-bit JVM has a performance penalty vs. the standard JVM. So more heap is probably not going to make your app run any better.

  • Set heap size websphere

    Hello
    i was playing around with websphere and increased the heap size from 3072 to 5072. Now when i tried to restart the server...it wont come back up. I cant getinto the Websphere administrative console either. does any one know a way to set the heap size thru command line back to 3072 for this server?
    thanks!

    http://www-1.ibm.com/support/docview.wss?rs=180&context=SSEQTP&dc=DB520&uid=swg21164724&loc=en_US&cs=utf-8&lang=en

  • Setting heap size through oracleAS 10.1.3 enterprise manager

    Hi All,
    Can any body pls tell me how we can set java heap size through oracleAS 10.1.3 enterprise manager
    Best Regards
    Girish Tandel

    hi...
    Yes, we can set the heap size in opmn.xml file in java-options.... But this is not the good practice to mannualy edit server xml files. In OracleAS 10.1.2 we can set the same through OEM. But i am not able to set using oem in oracleas 10.1.3
    Best Regards
    Girish

  • Setting Heap Size from JAR

    Hi,
    Does anybody know here how to specify the Heap size with JAR.
    From command line, I type java -jar -ms128M -mx350M IzoneIDE.jar
    My jar file is executable, so how can I specify the heap size in Jar Files.
    Please dont comment this as a Cross Post as I dont find any answer in Java Programming forum, thats why I post it here.
    Thanks
    Raheel

    Check here, http://java.sun.com/docs/books/tutorial/jar/
    not sure if the right info is there, but If you do find it pls let us know.
    ICE

  • Set heap size for applet

    I know that it is not allowed programmatically but what is syntex of the command to set max jvm. Which class name muste given in the command. I tried :
    java -Xmx128m
    if I write just like that, a screen shows as I write -help.
    Thank you

    I suspect you can't
    anything like that is restricted as it allows you
    access to the system.
    this prevents against the possibility overflow.
    though having said that , I don't know much about native methods in JAVA.

  • Plz can you help me. How to increase the Heap Size!!!!!!!!!!!

    Hi,
    i'm new to 10g appl server
    Failed to deploy web application "AGXI51". Failed to deploy web application "AGXI51". . The evaluate phase failed. The Adapter used in the evaluate may have thrown an exception.
    Resolution:
    Please call Oracle support.
    Base Exception:
    java.lang.OutOfMemoryError
    null. java.lang.OutOfMemoryError
    i'm getting this Error while deploying the application.So wat is the procedure to increase the Heap Size
    Regards,
    Niranjan.D

    Locate opmn.xml on your instance. In file locate section relevant for container you use (i.e. "home"). In next line you can see tags where startup parameters are set. You should add following parameters (this will set heap size on 512Mb)
    -Xms512m -Xmx512m
    For detailed explanation I would recommend you to check following link:
    http://download-uk.oracle.com/docs/cd/B25221_03/web.1013/b14431/troublesht.htm
    Hope this help.

  • Heap Size in 64 bit operating systems

    Hi,
    I have written a Java application which needs huge size heap. I tried to run the application under 32 bit windows operating system, but with 32 bit OS I got maximum heap size of 1.5 GB. To get more heap I have installed Windows 2003 Standard edition 64 bit version. Also I have installed JDK 1.7 64 bit for windows. I am using Netbeans IDE 6.7. I have configured Netbeans for 64 bit JVM. With this configuration I tried to set heap size of 1.6 GB it gives error "Could not create Java Virtual machine......". Also If I check proceess in task manager I see java.exe * 32 process. Does this mean JVM being used is still 32 bit JVM?
    Please let me know how to get more heap size under 64 bit OS?
    Regards,
    -Suresh Shirgave

    From a cmd window run a simple program using a 64-bit jvm (HelloWorld or similar) with different -Xmx values to establish the limit at which the program will run.
    <pathTo64-bitJVM>java -Xmxnn HelloWorldIf that's different from NB, then it's a setting of some kind in NB. Maybe you are pointing NB to a 32-bit JDK? Check the value in <NBInstallDirectory>\etc\netbeans.conf. If that's not it, check NB Help. You might want to ask the question at a NB forum, since this is a new version there may be a problem. Note that these forums are for Java language topics.

  • Retrieve Heap size from program

    Hi, i searched the foruns with "get heap size" and "retrieve size"
    and i also checked the System.getProperty(String key) string keys at
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperty(java.lang.String)
    and havent found a method to retrieve the currently set heap size.
    Is there a way to do this?
    My program needs to initialize something based on how large the
    user set the heap size (using the command line -Xms32m -Xmx128m...)
    Any info would be appreciated! Thanks alot!

    Touche!
    Thanks alot you pointed me in exactly the right direction.
    When i did research on java.lang.Runtime
    i found this post
    http://forums.java.sun.com/thread.jspa?threadID=529065&start=0&tstart=165
    which is a great two page thread on this subject.
    Runtime
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#maxMemory()

  • How to set the maximum heap size on a deployed application?

    I�m running a fairly large java application and am getting java.lang.OutOfMemoryError. I could increase the heap size in my development environment to eliminate this error. However, I don�t know how to set this in a deployed application. We are currently using ant to build our software.
    Another question, when I execute a statement such as java �Xmx512M �cp app.jar. Is it correct to say that the application in app.jar will use to a maximum of 512MB of memory when running?
    Thank you everyone for your help!

    But first, when you say "a deployed environment" do you mean an executable .jar file? This is what I'm using.The term "deploy" is commonly used to refer to deploying an ear file or a war file on an application server.
    I would assume that there is some entry you can include in the .jar's
    Manifest.mf file to specify the maximum memory, but I can't find an example of the entry. <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6197671"></a>

  • Set the heap size

    Hi,
    I am wondering what's the default heap size if I don't add -ms -mx opation? I
    set the two options and the following is the output from -verbosegc. what's it
    means?
    Thanks.
    [GC 2598K->2145K(2696K), 0.0035829 secs]
    [GC 2656K->2201K(2824K), 0.0036262 secs]
    [Full GC 2713K->2070K(4028K), 0.1933980 secs]
    [GC 2582K->2229K(4028K), 0.0046565 secs]
    [GC 2741K->2373K(4028K), 0.0061002 secs]
    [GC 2885K->2514K(4028K), 0.0064346 secs]
    [GC 3026K->2656K(4028K), 0.0061670 secs]
    [GC 3168K->2798K(4028K), 0.0054694 secs]
    [GC 3310K->2940K(4028K), 0.0054521 secs]
    [GC 3452K->3080K(4028K), 0.0058119 secs]
    [GC 3592K->3216K(4028K), 0.0059069 secs]
    [GC 3728K->3357K(4028K), 0.0057200 secs]
    [GC 3869K->3496K(4028K), 0.0055719 secs]
    [GC 4008K->3636K(4156K), 0.0057239 secs]
    [Full GC 4148K->3649K(6544K), 0.3064887 secs]
    [GC 4091K->3773K(6544K), 0.0412259 secs]
    [GC 4285K->3912K(6544K), 0.0052336 secs]
    [GC 4424K->4051K(6544K), 0.0055661 secs]
    [GC 4563K->4189K(6544K), 0.0055543 secs]
    [GC 4701K->4326K(6544K), 0.0055703 secs]
    [GC 4838K->4464K(6544K), 0.0055915 secs]
    [GC 4976K->4608K(6544K), 0.0059667 secs]
    [GC 5120K->4746K(6544K), 0.0053261 secs]
    [GC 5258K->4884K(6544K), 0.0053761 secs]
    [GC 5396K->5023K(6544K), 0.0059290 secs]
    [GC 5534K->5159K(6544K), 0.0054320 secs]
    [GC 5671K->5301K(6544K), 0.0114341 secs]
    [GC 5813K->5405K(6544K), 0.0103658 secs]
    [GC 5917K->5492K(6544K), 0.0053194 secs]
    [GC 6003K->5592K(6544K), 0.0107092 secs]
    [GC 6104K->5694K(6544K), 0.0096887 secs]
    [GC 6206K->5786K(6544K), 0.0037949 secs]
    [GC 6298K->5890K(6544K), 0.0101172 secs]
    [GC 6402K->5990K(6544K), 0.0041271 secs]
    [GC 6502K->6097K(6672K), 0.0040678 secs]
    [Full GC 6609K->6191K(10992K), 0.2664733 secs]
    Tue Dec 04 15:22:10 PST 2001:<I> <T3Services> CacheManagerImpl: EMAIL TEMPLATE
    C
    ACHE STARTING
    [GC 6849K->6361K(10992K), 0.0586387 secs]
    Tue Dec 04 15:22:10 PST 2001:<I> <T3Services> CacheManagerImpl: SCHEDULE CACHE
    S
    TARTING
    [GC 7129K->6530K(10992K), 0.0083019 secs]
    [GC 7298K->6678K(10992K), 0.0058533 secs]
    [GC 7446K->6807K(10992K), 0.0052940 secs]
    [GC 7575K->6920K(10992K), 0.0048598 secs]

    I think the default heap size is 16MB, as for the GC output:
    these [GC 2598K->2145K(2696K), 0.0035829 secs]
    show the collection of Objects within the eden area of the heap (Short lived Objects),
    the heap size before GC was 2598K and after GC was 2145K and the time taken was
    0.0035829 secs.
    These outputs:
    [Full GC 2713K->2070K(4028K), 0.1933980 secs]
    show the details for a full GC, these are the ones to watch out for, they will
    take longer and the JVM (no mater how many processors) will block during a full
    GC....I.E no server response at all.
    The smaller the heap size the more often a full GC will occur, however the larger
    the heap, the longer the full GC will take.
    One of the new options for jdk 1.3.1 is the -Xincgc option, this will do incremental
    Garbage Collection, overall it will take longer than normal, but the individual
    Full GCs will take less time....so the server is not hung for as long at any one
    time.
    Set -Xms (the minimum heap) to the same as -Xmx (max heap), this increases performance
    as the JVM does not have to repeatedly assign more memory to the heap.
    Gareth
    "Jen" <[email protected]> wrote:
    >
    Hi,
    I am wondering what's the default heap size if I don't add -ms -mx opation?
    I
    set the two options and the following is the output from -verbosegc.
    what's it
    means?
    Thanks.
    [GC 2598K->2145K(2696K), 0.0035829 secs]
    [GC 2656K->2201K(2824K), 0.0036262 secs]
    [Full GC 2713K->2070K(4028K), 0.1933980 secs]
    [GC 2582K->2229K(4028K), 0.0046565 secs]
    [GC 2741K->2373K(4028K), 0.0061002 secs]
    [GC 2885K->2514K(4028K), 0.0064346 secs]
    [GC 3026K->2656K(4028K), 0.0061670 secs]
    [GC 3168K->2798K(4028K), 0.0054694 secs]
    [GC 3310K->2940K(4028K), 0.0054521 secs]
    [GC 3452K->3080K(4028K), 0.0058119 secs]
    [GC 3592K->3216K(4028K), 0.0059069 secs]
    [GC 3728K->3357K(4028K), 0.0057200 secs]
    [GC 3869K->3496K(4028K), 0.0055719 secs]
    [GC 4008K->3636K(4156K), 0.0057239 secs]
    [Full GC 4148K->3649K(6544K), 0.3064887 secs]
    [GC 4091K->3773K(6544K), 0.0412259 secs]
    [GC 4285K->3912K(6544K), 0.0052336 secs]
    [GC 4424K->4051K(6544K), 0.0055661 secs]
    [GC 4563K->4189K(6544K), 0.0055543 secs]
    [GC 4701K->4326K(6544K), 0.0055703 secs]
    [GC 4838K->4464K(6544K), 0.0055915 secs]
    [GC 4976K->4608K(6544K), 0.0059667 secs]
    [GC 5120K->4746K(6544K), 0.0053261 secs]
    [GC 5258K->4884K(6544K), 0.0053761 secs]
    [GC 5396K->5023K(6544K), 0.0059290 secs]
    [GC 5534K->5159K(6544K), 0.0054320 secs]
    [GC 5671K->5301K(6544K), 0.0114341 secs]
    [GC 5813K->5405K(6544K), 0.0103658 secs]
    [GC 5917K->5492K(6544K), 0.0053194 secs]
    [GC 6003K->5592K(6544K), 0.0107092 secs]
    [GC 6104K->5694K(6544K), 0.0096887 secs]
    [GC 6206K->5786K(6544K), 0.0037949 secs]
    [GC 6298K->5890K(6544K), 0.0101172 secs]
    [GC 6402K->5990K(6544K), 0.0041271 secs]
    [GC 6502K->6097K(6672K), 0.0040678 secs]
    [Full GC 6609K->6191K(10992K), 0.2664733 secs]
    Tue Dec 04 15:22:10 PST 2001:<I> <T3Services> CacheManagerImpl: EMAIL
    TEMPLATE
    C
    ACHE STARTING
    [GC 6849K->6361K(10992K), 0.0586387 secs]
    Tue Dec 04 15:22:10 PST 2001:<I> <T3Services> CacheManagerImpl: SCHEDULE
    CACHE
    S
    TARTING
    [GC 7129K->6530K(10992K), 0.0083019 secs]
    [GC 7298K->6678K(10992K), 0.0058533 secs]
    [GC 7446K->6807K(10992K), 0.0052940 secs]
    [GC 7575K->6920K(10992K), 0.0048598 secs]

  • Upto how much I can set maximum Heap size for jvm?

    I am running application on 8GB RAM Windows 64 bits machine.
    I am running out of OutOfMemory (Heap Space). I want to increase the Heap Size for my jvm.
    But can anybody please tell me what is the limit by which I can set the maximum size for heap?
    Thanks in Advance,
    Jenish

    Max allowed memory per process is 2 raised to the 64th power. What maximum memory you can set depends on the memory available
    for your application. You may be able to set more than 8GB ram then it will use the swap space and it will slow down your application
    performance. So try different memory size and see which one works best for your application.

  • How to set the heap size of JVM

    please let me know that how to set the heap size of JVM

    C:\>java -X
        -Xmixed           mixed mode execution (default)
        -Xint             interpreted mode execution only
        -Xbootclasspath:<directories and zip/jar files separated by ;>
                          set search path for bootstrap classes and resources
        -Xbootclasspath/a:<directories and zip/jar files separated by ;>
                          append to end of bootstrap class path
        -Xbootclasspath/p:<directories and zip/jar files separated by ;>
                          prepend in front of bootstrap class path
        -Xnoclassgc       disable class garbage collection
        -Xincgc           enable incremental garbage collection
        -Xbatch           disable background compilation
        -Xms<size>        set initial Java heap size
        -Xmx<size>        set maximum Java heap size
        -Xss<size>        set java thread stack size
        -Xprof            output cpu profiling data
        -Xrunhprof[:help]|[:<option>=<value>, ...]
                          perform JVMPI heap, cpu, or monitor profiling
        -Xdebug           enable remote debugging
        -Xfuture          enable strictest checks, anticipating future default
        -Xrs              reduce use of OS signals by Java/VM (see documentation)look at the -Xm? lines
        -Xms<size>        set initial Java heap size
        -Xmx<size>        set maximum Java heap sizeThis can be used e.g. like this:java -Xms8M -Xmx32M MyProgwhich runs MyProg in a java VM with the initial heap size of 8 MB and a maximum heap size of 32 MB.
    - Marcus

Maybe you are looking for

  • Planning web forms are not opening in EPM11..

    Hi Gurus, Planning web forms are not opening in EPM11.. What logs i need to check in these case, what should be the path of the logs. Here i am accesing web forms on my local system through workspace web link We have 2 essbase server and three applic

  • IMovie 6.0.3 timeline conundrum: adding photo without losing sync

    How does one add a photo to an existing video with audio in 6.0.3 so that it simply replaces, for example, 5 seconds of the video WITHOUT moving the rest of the video?  IOW, I don't want the video or audio to move at all, just for the inserted image

  • Audio missing on playback. Sony GV-D300.

    There is audio showing in the meter on playback and I can hear audio when I play something in iTunes but there is no sound from Final Cut Express - this has become a recurring problem. The guys at tech support suggested I dump the Final Cut folder an

  • How tp run JSTL ?

    hello, i'm new to JSP technology can anybody plz help me out to solve i'm getting problem in i embedded few JSTL tags in my JSP page the tags are fmt & core c also used expression language to display my result in the web-INF directory i copied jar fi

  • Report header Dynamic FR

    Dear gurus I have taken entity in Page  When i select entity in drop down Different entity have different header of the report how can i do that Please help Thanks in advance