Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

memory is allocated to the JVM to run the java application

Posted on 2014-02-11
6
Medium Priority
?
1,103 Views
Last Modified: 2014-02-22
Hi,

I was reading as

 'memory is allocated to the JVM to run the java application'


How and who allocate memory to JVM. I never remember allocating memory to JVM on my windows laptop. What is the maximum memory i can allocate to JVM.


I see my windowns 7, 64 bit laptop has installed memory(RAM) of 8 GB. How and where to assign memory to jvm. By default how much memory is allocated to JVM. Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 1200 total points
ID: 39851455
Here is a website that has options for setting your JVM.

http://docs.oracle.com/cd/E15523_01/web.1111/e13814/jvm_tuning.htm



-Xms512m : this sets initial and minimum heap size to 512 MB
-Xmx512m: this sets maximum heam size to 512 MB  

Example usage :

 java -Xms512m -Xmx512m

I've attached a screenshot of how/where you would set them if you are using eclipse.

in eclipse you would right click on your project and select properties.
From there you select run/debug setttings and then create or edit your Launch Configurations.

From there you select the "arguments" tab.  That is the screenshot I've attached here.

NOTE : the version of eclipse that this screenshot is taken from is Kepler.


The eclipse.ini file can also be used to hold the default values for memory to allocate to the JVM.  (see following link for details)

http://wiki.eclipse.org/Eclipse.ini
2-11-2014-2-53-27-PM.jpg
0
 
LVL 7

Author Comment

by:gudii9
ID: 39857550
As in attachment do i need to set(like -Xms512m) for every java program i run.

What is the default value.

 java -Xms512m -Xmx512m


what is the difference between initial and maximum heap size. Can they be same?

Please advise
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39857579
The default is defined in your eclipse.ini file.

For example... my eclipse is installed at :

C:\Program Files (x86)\eclipse

in that folder is eclipse.ini.

inside eclipse.ini is following:

-Xms40m
-Xmx512m

Initial and maximum heapsize can be the same.

The difference is initial Heap size is the size that will be allocated to heap when the JVM first starts.  

If more is needed then heap size will be increased up to maximum of whatever is defined for Maximum heap size.

If you set maximum size = initial heap size... then heap size cannot be increased if JVM runs out.

You only need to worry about it if your particular java application runs out of memory.

The default values in eclipse.ini file can be overridden for a specific java application by following instruction in my previous post ---> here : http://www.experts-exchange.com/Programming/Languages/Java/J2EE/Q_28362322.html#a39851455
0
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 7

Author Comment

by:gudii9
ID: 39870591
I checked eclipse.init file it shows me

-Xms40m
-Xmx512m

same as yours.

The difference is initial Heap size is the size that will be allocated to heap when the JVM first starts.


When the JVM starts ? is it at the start of the eclipse or is it start of the web or application server like tomcat/weblogic etc within the eclipse.
Is there is separate jvm for eclipse and web or application server?

please advise
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39870680
This is getting off topic from your original question....
How and who allocate memory to JVM.

I'd really rather not chase down a bunch of new questions within this thread as that can go on forever.

That being said... eclipse is an IDE... a development environment.  it includes all sorts of tools to make development in Java easier.

For example ... when you use eclipse... and tell it to start your java application... it will issue the javac command to compile your changed source files.  You don't have to specifically type "javac"... but eclipse will do it for you when you build your project or when you start your application.

You could do the same thing at a DOS prompt... it's just more cumbersome.

Likewise... whenever you start a Java Application... regardless of whether it is in Eclipse, the DOS prompt, or on a web server... That invocation of the java application will require that a JVM be present to execute the bytecode.  

So yes... there is a separate instance of the JVM for a web server, than there is for the case where you are running it locally within eclipse.

Within eclipse you can also include and start up a webserver, like Apache Tomcat or whatever... but no matter how it is done.. in the end... there is a JVM that must be running to execute your code... and the memory allocated to that specific JVM may need to be adjusted for your specific situation.
0
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 800 total points
ID: 39872260
More to the point of your question... Yes, there is a JVM that starts up to run Eclipse (as it itself is a Java application) and then when you issue the command in Eclipse to execute your application, whether it is a standalone program or a web app etc, a new separate JVM will be started to run your code.

The settings in eclipse.ini will only affect the JVM for Eclipse. If you want to control any memory settings for your application you can setup "Run configurations" to pass those settings to the JVM created for your app.
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question