• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System Property Setting and JVM

 
Gil Li
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello people..
I have set a value to System property like
System.getProperties().put("name","ram");

in one servlet and I got exactly the value of the key "name" in
another servlet by using..

System.getProperties().get("name");

But When I do this in normal java file and access the value in anotherjava file I did not get the value.It returns null.Actually when we set theSystem Property value that will be stored in JVM. So why that value is notget in ordinary java files.It works well in servlets.Please clear my doubt.
 
Anupreet Arora
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gil,

The explanation for this is that servlets are deployed in a servlet container and they use the JVM of the container. So if many servlets are deployed in the same container, they are using the same JVM . Hence different servlets can see the same JVM specific system property.

This is not the case for simple java programs. Each execution is in a separate JVM. So the system property you are adding to the JVM gets lost after the execution.

Cheers
Anupreet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic