Hi I need to know one basic thing in a servlet. What is the difference between a Class Variable and a static variable in a Servlet (Servlet that does not implement SingleThreadModel Interface). Thanks a Bunch!!! Chandar S. Vel.
A static and class variable are one and the same thing. They are shared by all instances of the servlet, and are never thread-safe, even if the SingleThreadModel interface is implemented (multiple threads may access the same static variable from different servlet instances). Perhaps you wanted to know the difference between class and instance variables in a servlet? Instance variables are also not thread-safe as they can be shared by more than one thread servicing the same servlet instance. They are thread-safe, however, if the SingleThreadModel interface is implemented since only one thread may service an instance at a time. Hope this helps. Mark.
Mike - I have always seen "class variable" and "static" used interchangably with "instance" variable as clearly different. Admittedly "class variable" is a sloppy usage when "static" is clearer, but that is the way I have seen it used. Bill
you know, i waffled back and forth about posting. I knew there was something not right about the post. Was I completely insane? Or was I right? I got caught up in terminology. Sigh. Is it a bad thing that I'm supposed to write my cert. exam on Friday?
Right you are Bill and mark. 'static implies class'. My thinking error came about because in my head I was saying "variables at the level of the class" (as opposed to "method level"). Which in *THAT* thinking space, could be either static or not.
I knew something was fishy. Sorry for the confusion.
No sweat Mike, do it all the time myself. A bit like the words "lose" and "loose", which must be the most commonly misused words in the English language. But you get so used to their misuse that the difference becomes unclear after a while. You certainly had me having a hard look at the words "static" and "class" again Good luck for Friday.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop