Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Static methods thing

Thread view: 
vahid.xplod@gmail.com - 17 Mar 2006 17:11 GMT
hi , can anyone tell me that when i declare field or method as static,
whether for each user who connect to the server we have a static method
or we have one static method for all users in the same server and that
static method is shared between all users ?
Hendrik Maryns - 17 Mar 2006 17:32 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

vahid.xplod@gmail.com schreef:
> hi , can anyone tell me that when i declare field or method as static,
> whether for each user who connect to the server we have a static method
> or we have one static method for all users in the same server and that
> static method is shared between all users ?

There is one method bound to the class.  So al long as you don't start
doing things with ClassLoaders, you will only have one method.  Per JVM,
that is.

H.
Signature

Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org

marcwentink@hotmail.com - 17 Mar 2006 17:32 GMT
Well I am not 100% sure because I do not know how your application is
working. With a static you have one item for all instances of a class.
Hence if you have one java application and one VM serving all users,
then all users have that one static, since there is one static in the
application. If you start a different VM for each request, which is
more common, you have one static per session, and hence more or less
one per user.

Marcus Wentink
lewmania942@yahoo.fr - 17 Mar 2006 18:51 GMT
> Well I am not 100% sure because I do not know how your application is
> working. With a static you have one item for all instances of a class.
[quoted text clipped - 3 lines]
> more common, you have one static per session, and hence more or less
> one per user.

"If you start a different VM for each request, which is more common,
..."

Did you really meant that?

For what kind of "request" is it common to "start a different VM" ?
Marcus - 17 Mar 2006 18:59 GMT
<lewmania942@yahoo.fr> schreef

> "If you start a different VM for each request, which is more common,
> ..."

> Did you really meant that?

No, you are right, I was mistaking. The rest was quite valid though I think?
Oliver Wong - 17 Mar 2006 19:34 GMT
>> Well I am not 100% sure because I do not know how your application is
>> working. With a static you have one item for all instances of a class.
[quoted text clipped - 10 lines]
>
> For what kind of "request" is it common to "start a different VM" ?

   I wouldn't be too surprised if I found out a particular server did this.
While performance may take a hit, it leads to the server as a whole being
much more robust to erroneous JSP code.

   You might even be able to set it up so that there's a seperate JVM for
each web app (i.e. so that you and I both share the same server, if I write
buggy code, it won't break your code).

   - Oliver
James McGill - 17 Mar 2006 22:36 GMT
>     I wouldn't be too surprised if I found out a particular server did
> this.  

I'd like to know of one that does, for security reasons, not
performance.
Oliver Wong - 17 Mar 2006 23:04 GMT
>>     I wouldn't be too surprised if I found out a particular server did
>> this.
>
> I'd like to know of one that does, for security reasons, not
> performance.

   Out of curiosity, are you saying that having a seperate VM per
request/app/whatever poses a security risk? If so what, risk might that be
(other than denial of service attacks, which in the end are actually a
performance issue)?

   - Oliver
James McGill - 17 Mar 2006 23:26 GMT
>     Out of curiosity, are you saying that having a seperate VM per
> request/app/whatever poses a security risk?

Not at all.  I'd like to provide JSP capability to people using a shared
web server, but the only servers I know about use a single JVM, and I
can't have that for security reasons.
Thomas Hawtin - 18 Mar 2006 17:51 GMT
> Not at all.  I'd like to provide JSP capability to people using a shared
> web server, but the only servers I know about use a single JVM, and I
> can't have that for security reasons.

You should find each web app has a different class-loader, much like
different web pages of applets. Tomcat, and I believe other Servlet
containers, allow individual security policies. The difficulty comes in
that Servlet containers and the class-loader mechanism aren't really
optimised to do this sort of thing on a large scale.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

VisionSet - 17 Mar 2006 17:33 GMT
> hi , can anyone tell me that when i declare field or method as static,
> whether for each user who connect to the server we have a static method
> or we have one static method for all users in the same server and that
> static method is shared between all users ?

You only have one static method per classloader (or is that per JVM?) But
that is irrelevant because even if it were an instance method all callers
get their own copy of the local variables declared within, so the
distinction between static and instance method is not important.  What is
important is that you realise a servlet by default is multithreaded and
exists as a single instance.  Therefore attributes and static members are
shared amongst all users.  You used to be able to declare a single threaded
model, where a servlet instance was created for each request, it was then
intrinisically thread safe.

But to answer your question simply, all users get there own copy.

--
Mike W
Oliver Wong - 17 Mar 2006 18:20 GMT
> hi , can anyone tell me that when i declare field or method as static,
> whether for each user who connect to the server we have a static method
> or we have one static method for all users in the same server and that
> static method is shared between all users ?

   As you may have noticed, you've been getting mixed replies to this
question, and that is because it depends largely on how your server and
framework is configured. It's best to design your code so that you do not
depend on on this behaviour one way or the other. If you need to share data
between users, consider storing that data in a database, for example.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.