Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access right to Static key word - same jvm - difference application

 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have 3 application running in tomcat server shares the same jvm and i have used static key word with public access on app1 and i try to use that in app2, will it be posible to access it?

Note: basically once the the static varible loadded in to jvm which shared across between application it should be accessable if not please let me know the reason.
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean by 3 application

Are they web application.

Anyways answer to your question is yes
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish Singh wrote:what do you mean by 3 application

Are they web application.

Anyways answer to your question is yes


Yes, 3 are web application only.

I searched in the google and i could not get the reason of it so can you please let me know because such a case the static variable accessable between application then it is not secure?

 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to learn about the tomcat class loaders.

The classes you want to use across the web applications should be packaged in a jar and put in the shared folder of tomcat.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish Singh wrote:You need to learn about the tomcat class loaders.

The classes you want to use across the web applications should be packaged in a jar and put in the shared folder of tomcat.


thanks and your point. my question, it is not good thing to use static variable in application because it is not secure one and also if we use more static variable then the system performance also go down. i feel the we should not use static variable more is that correct?
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We make use of the static variables to store the compile time constants in our project.

I don't think there is any performance degradation by use of static vars
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static variable is shared among all instances of a class. Java defines a class as something loaded out of a .class file by a particular class loader. This means that if two copies of the same .class file are loaded by two different class loaders -- as would be the case if the class is installed in two different web apps -- then those are actually not the same class, and each one has its own copy of that static variable. There's no interference between the apps.
 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you mentioned two class loaders from two web apps. But, i need to restrict the classes between UI package to Service Package with in same JVM. i meant, there will be a class loader for each layer package and i need to restrict the UI layer package class access with service layer package class. please share me some example to implement this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic