-3

Suppose I start an application server and lunch a web page that is being deployed under this Applicatin server . This page have some links (urls) that call (each one) a diffrent main method in the Application sever deployed code (war) . How does each main method "knows" not to start a new JVM but to run all under the Application Server JVM ?

user3138101
  • 83
  • 1
  • 13
  • Since when does a `main` method start a JVM instance? More likely a new JVM instance runs the specified `main` method during application start. – Tom Jan 04 '15 at 22:00
  • and what triggered a new JVM instance ? – user3138101 Jan 04 '15 at 22:05
  • *You* do. Either by calling `java -jar ...` or by starting the application server or something else. – Tom Jan 04 '15 at 22:06
  • right . ok . so my question : how my call to java myMain1Method not start a new JVM instance while code is running under the Application server JVM – user3138101 Jan 04 '15 at 22:12

1 Answers1

1

A Java web application deployed from a war file doesn't have multiple main methods (aka entry points). Each servlet or JSP (which is compiled to a servlet) is accessed by the service method (as documented in the Servlet specification as the Servlet life-cycle);

init()    // <-- called once
service() // <-- called multiple times, once for each request
destory() // <-- called once

The Java EE Tutorial documents the Servlet life-cycle in great detail.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • as I mention : some web page has link that call:java myMain1Method , java myMain2Method .. and so on. this has nothing to do with the servlet API – user3138101 Jan 04 '15 at 22:16
  • No. If it has nothing to do with the servlet API, why are you talking about war files? Post working code, because that can't be correct. Do you mean `javascript:`? – Elliott Frisch Jan 04 '15 at 22:17
  • I will post the code . But do you claim war file can not have many main methods in many different classes in it ? – user3138101 Jan 04 '15 at 22:24
  • You can put as many `main` methods as you like in a war file, but **none** of them will ever be executed by a Web Application Server. – Elliott Frisch Jan 04 '15 at 22:25
  • What do you mean : by a Web Application Server ? The user hit the link and it call the main method. I will check exectly how the call looks like – user3138101 Jan 04 '15 at 22:26
  • An JEE container certified with the Web Profile. Apache Tomcat. WebSphere. Weblogic. JBoss. Etc. – Elliott Frisch Jan 04 '15 at 22:28
  • yes sure , JBoss in this case . – user3138101 Jan 04 '15 at 22:30