aspose file tools*
The moose likes Java in General and the fly likes access right to Static key word - same jvm - difference application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "access right to Static key word - same jvm - difference application" Watch "access right to Static key word - same jvm - difference application" New topic
Author

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

G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
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.


Thanks
Sathish kumar
SCJP, SCWCD
Manish Singh
Ranch Hand

Joined: Jan 26, 2007
Posts: 160
what do you mean by 3 application

Are they web application.

Anyways answer to your question is yes
G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
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

Joined: Jan 26, 2007
Posts: 160
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

Joined: Jul 27, 2009
Posts: 84
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

Joined: Jan 26, 2007
Posts: 160
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access right to Static key word - same jvm - difference application