Reputation: 23634
A runtime instance of the Java virtual machine has a clear mission in life: to run one Java application. When a Java application starts, a runtime instance is born. When the application completes, the instance dies. If you start three Java applications at the same time, on the same computer, using the same concrete implementation, you'll get three Java virtual machine instances. Each Java application runs inside its own Java virtual machine.
I was going through this article on run-time instance, i was just not clear about the lines above.
public class Test1 {
public static void main(String args[]) {
if (args.length > 0) {
try {
for (int i = 0; i < args.length; i++) {
System.out.println("Args" + args[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
When i run the above class, a runtime instance is born. Once it completes it operation, the runtime-instance dies off.
Let's take stackoverflow.com
is hosted some where on the web, does one runtime-instance of the app is enough to serve the people or depending on the load and traffic do we create different instance of the same app on different servers/computers. How and when do you decide we need to create different instances of the same app?
What does the same concrete implementation
mean here? How about different concrete implementations.
I am sorry if my questions are quite vague in any manner, i am learning java but purely working on HTML/CSS and JS
.
http://www.artima.com/insidejvm/ed2/jvm.html
Upvotes: 4
Views: 2595
Reputation: 86
1:
How and when would you decide to create different instances of the same app?
If, for example you wanted an app that would be located close to the user, then you could deploy one of them on a server in Asia, one in EMEA, and on in the USA. When your user tries to access it, you route them to the server closest to you and they get the most responsive user experience possible.
Now - this is not possible in all instances, as if you are sharing data (for example, if you were a bank), then you would have to manage the data in a way that makes it consistent across the three instances of your application. That though is perhaps a topic for a different question.
2: Same concrete implementation. This is typically used when you are referring to an abstract class, and choose to have a specific implementation of a class. For example - if you have the abstract class "Car" and have a concrete implementation that implements if of "Ferrari".
In this case, it is using the same terminology, but in a way that is not that common. When the text refers to the concrete implementaiton in this context, it is saying that it is the same program. i.e. you copy and paste the ".exe" and run it again. In Java terms, you would copy the same ".jar" files, and execute it.
However in this case, you could be doing it on different machines, or as stated, you could run them on the same computer, and if you looked in memory you would see three separate java processes.
Upvotes: 1
Reputation: 75376
Java machines for personal computers are programs like Word or Internet Explorer or Adobe Reader.
The way they are designed is that if you run three Java programs at the same time, each program has its own JVM started to handle it, as opposed to having multiple tabs open in a single browser windows).
The word instance refers to the operating system considering them as running programs and not just files on your harddisk with a lot of bytes that happen to be named EXE.
Concrete implementation refers to a given installation of Java in e.g. C:\Programs\Java\Java-7.1.2.3\bin\java.exe
. If you run this program three times, you will have three running instances and not just only one.
Upvotes: 1
Reputation: 240900
quite vague: right and so is the answer
2 concrete implementation is a class which has implementation for all of its method (unlike abstract class/ interface)
1 You could stretch your app horizontally if required in cloud based deployment
Upvotes: 1