Servlets and their instance variables

I understand that for every request to a servlet, a new thread handles those requests. So it's one request, one thread. But how about instance variables of a servlet class? Are they also one instance variable per thread/request or just like the servlet, one instance?

hi, its exactly as you expect - one instance at all. all threads are working with one intance. you can indeed finetune the number of instances of a servlet using the
<load-on-startup/>tag in the web.xml file, but its up to container if multiple thread will be using many instances.
you can also implement the (deprecated) SingleThreadedModel interface which flags the container not to share that servlet instance to other threads. But this shall not be used in productive environments.
so its always a good idea to put your business impleementation to another class and only use the servlets to connect your business implementation to http like
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException{
   new MyBusinessLogic().perform(request.getInputStream(), response.getOutputStream());
}

Similar Messages

  • Inheritance and private instance variables

    I've been reading a Java book. It says you should normally make your instance variables private and use getter/setter methods on them, but if you create a superclass, you have to make those variables public (or default?) to inherit them in the subclasses, right? And you can't redefine the variables as private in the subclass, can you?
    I'm a little confused on this point. Thanks for any light anyone could shed on this.
    =====
    Nevermind...I think I figured it out!
    Message was edited by:
    NovaKane

    Thanks to both of you for your responses. I think I've pretty much done what you did, Anan, in this little test program.
    public class Animal
       private String name=null;
       public void setName(String n)
          name=n;
       public String getName()
         return name;
       public void makeSound()
    public class Dog extends Animal
       public void makeSound()
          if (getName() !=null)
             System.out.println(getName()+" says, \"Bow Wow!\"");
          else
             System.out.println("I don't have a name...but \"Bow Wow!\"");
    public class Cat extends Animal
       public void makeSound()
          if (getName() != null)
             System.out.println(getName()+" says, \"Meow!\"");
          else
             System.out.println("I have no name...but, \"Meow!\"");
    import java.util.*;
    public class Test
       public static void main(String[] vars)
            ArrayList<Animal> animals = new ArrayList<Animal>();
            Animal d = new Dog();
            Animal c = new Cat();
            d.setName("Fido");
            c.setName("Fluffy");
            animals.add(d);
            animals.add(c);
            for (Animal a : animals)
                a.makeSound();
    }The "name" instance variable is private, but I can get at it through the getter/setter methods of the superclass, which are public. I should NOT be able to say something like...
    d.name="Fido";Right?

  • Servlet and Class instances

    Under normal conditions a web-container creates only one instance of servlet.Now the case is I am creating instance of a class in the servlet.So for every request to the servlet does an instance of the class is created?

    If you make the instance in a service method (service(), doGet(), doPost() etc...) then yes, each request will create a new instance.
    If you create the instance anyplace else, no they will share it.
    If you hold the reference to the class in the servlet class level as opposed to storing it in the method which creates and uses it, then you can run into problems as well, since there will be only one reference for all requests.
    So generally speaking in Servlets (and in any application you need to worry about thread safety:
    This is bad. One object will be used by all requests:
    public class BadServlet ... {
        Object myObject = new Object();
        public void doGet(...) ... {
            do something with myObject;
    }This is bad. A new instance is made for each request, but only one reference. So one request will end up using another's instance:
    public class BadServlet ... {
        Object myObject;
        public void doGet(...)... {
            myObject = new Object();
            do something with myObject;
    }This is how you would do it in a thread safe manner:
    public class GoodServlet ...{
        public void doGet(...)... {
            Object myObject = new Object();
            //Another method in same class needs a reference?  Pass it as a parameter
            someOtherMethod(myObject);
            //Some other servlet needs access?  Store it in Request scope
            request.setAttribute("myObject", myObject);
            //Some other request needs to access it?  Put it in the session scope
            HttpSession session = request.getSession();
            session.setAttribute("myObject", myObject);
        private void doSomething(Object myObject) ... {
            do something with myObject
    }

  • Listing objects and their instance names (of closed source SWF)

    I have an API for a flash player that I want to use, but it is closed source. I know I could try a decompiler but I need to see what it loads and what it's doing at runtime.
    I'd like to see the objects (and all their info) that it loads and has on stage along with thier instance names. I'd like to see what this SWF has/does so I can write my AS3 code accordingly... maybe add some additional event listeners.
    Is there any was to go about doing this? I know there's some AS3 commands to get this information but I dont know what they are. If you all could give me some hints at which commands would be useful that would be great.

    "I need to see what it loads"
    You can use Fiddles, Charles or Firebug to monitor traffic (what it loads).
    As for the rest of your question - good luck. Although it is possible to decompile swf of course, reverse engineering is an extremely complex time consuming task. In the majority of cases it is easier and faster to replicate functionality from scratch than to try to understand SWF's logic.
    Unless you know packages structure - there is no native way to figure out/access application domain.

  • What's the difference between global variables and instance variables?

    hi im just a biginner,
    but what is the difference between these two?
    both i declare them above the constructor right.
    and both can access by any method in the class but my teacher said
    global variables are not permitted in java....
    but i don't know what that means....and i got started to confuse these two types,,
    im confusing.......
    and why my teacher said declaring global variables is not permitted,,,,,,
    why.....

    instance variables are kindof like Global variables. I'm not surprised you are confused.
    The difference is not in how they are declared, but rather in how they are used.
    There are two different "styles" of programming
    - procedural programming.
    - object oriented programming.
    Global variables are a term from Procedural programming.
    In this style of programming, you have only one class, and one "main" procedure. You only create one instance of the class, and then "run" it.
    There is one thread of control, which goes through various methods/procedures to accomplish your task.
    In this style of programming instance variables ARE "global" variables. They are accessible to all methods. There is only one instance of the class, and thus only one instance of the variables.
    Global variables are "bad" BECAUSE you can change them in any method you like. Even from places that shouldn't have to. Also if you use the same name as a global variable and a local variable, you can cause great trouble. This can lead to very subtle bugs, as the procedures interact in ways you don't expect.
    The preferred method in procedural programming is to pass the values as parameters to the methods, and only refer to the parameters, and local variables. This means that you can track exactly what your method is doing, and what it affects. It makes it simpler to understand. If you use global variables in your methods, it becomes harder to understand.
    So when are instance variables not global variables?
    When you are actually using the class as an Object, rather than just a program to run. If you are creating multiple instances of an object, all with different values for their instance variables, then they are not global variables. For instance you declare a Person object with an attribute "firstname". Your "main" program then creates many instances of the Person object, each with their own "firstname"
    I guess at the end of all this, it comes down to definitions.
    Certainly you can write procedural code in java. You can treat your instance variables, for all intents and purposes like global variables.
    I can only think to show a sort of example
    public class Test1
       User[] users;
       public void printUsers(){
         // loop through and print all the users
         // uses a global variable
          for(int i=0; i<users.length; i++){
            users.printUser();
    public void printUsers(User[] users){
    // preferred method - pass it the info it needs to do the job
    for(int i=0; i<users.length; i++){
    users[i].printUser();
    public Test1(){
    User u1 = new User("Tom", 20);
    User u2 = new User("Dick", 42);
    User u3 = new User("Harry", 69);
    users = new User[3];
    users[0] = u1;
    users[1] = u2;
    users[2] = u3;
    printUsers();
    printUsers(users);
    public static void main(String[] args)
    new Test1();
    class User{
    String firstName;
    int age;
    public User(String name, int age){
    this.firstName = name;
    this.age = age;
    public void printUser(){
    // here they are used as instance variables and not global variables
    System.out.println(firstName + " Age: " + age);
    Shit thats a lot of typing, and I'm not even sure I've explained it any good.
    Hope you can make some sense out of this drivel.
    Cheers,
    evnafets

  • JDEVELOPER 10G, ADF BC: Passivate static instance variables in AM?

    I understand the need to passivate/activate instance variables but what about static instance variables within an application module?
    Thanks,
    Wes

    Static variables - being class variables and not instance variables - persist without a need for passivation. Is there a particular reason or scenario why to use static variables? You have to consider that since all AM instances will share it, changing it in one AM instance - i.e. one user session - will affect all other AM instances - i.e. all other user sessions! You also have to consider the implications of multithreading when attempting to modify the static variable.

  • Design question: When to use instance variables

    Looking for best practice/design advise.
    I am working my way through an exercise where I convert a zip code to a postal barcode (and back), validate the format, and validate/generate a check digit. My code works fine. I posted comments and methods below for reference. In addition to the book I am using, I also read http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html.
    My question is: In designing this class, should I have defined instance variables to hold the generated zipcode, barcode, and checkdigit and then used getter methods to get the zipcode or barcode?
    I planned on creating a user interface to ask for a zipcode or barcode and present a conversion to the user. The only methods that need to be called are "convertBarcodeToZipcode" and "convertZipcodeToBarcode". All the other methods are utility methods. The strings that are returned by these two methods are presented to the user.
    I could, easily enough, create and populate instance variables, but would I keep the return statements as well or remove them?
    Thanks, Mike
    ps: I am self-learning java, so I don't have an instructor to ask. :)
    public class PostalBarCode {
         * Constructor.
         * Set up the barcode ArrayList
        public PostalBarCode() {
                barcodeUnits.add("||:::");
                barcodeUnits.add(":::||");
                barcodeUnits.add("::|:|");
                barcodeUnits.add("::||:");
                barcodeUnits.add(":|::|");
                barcodeUnits.add(":|:|:");
                barcodeUnits.add(":||::");
                barcodeUnits.add("|:::|");
                barcodeUnits.add("|::|:");
                barcodeUnits.add("|:|::");
         * Convert a barcode to a zipcode.
         * Assumes the input format is valid. Validates the check digit
         * @param theBarcode string to be converted
         * @return the zipcode as a String of empty string for error
        public String convertBarcodeToZipcode(String theBarcode) {}
         * Convert the Zipcode to a barcode
         * @param theZipcode string to be converted
         * @return the barcode as a string
        public String convertZipcodeToBarcode(String theZipcode) {}
         * Determines if theString is a barcode
         * @param theString
         * @return true if the input is a barcode, false otherwise.
        public boolean isBarcode (String theString) {}
         * Determines of theString is a zip code
         * @param theString the string to test for 5 digits
         * @return true for a zip code, false otherwise
        public boolean isZipcode (String theString) {}
         * Convert a barcode to a zipcode.
         * Assumes the input format is valid. Validates the check digit
         * @param theBarcode string to be converted
         * @return the zipcode as a String of empty string for error
        public String convertBarcodeToZipcode(String theBarcode) {}
         * Convert the Zipcode to a barcode
         * @param theZipcode string to be converted
         * @return the barcode as a string
        public String convertZipcodeToBarcode(String theZipcode) {}
         * Calculate the check digit from the zipcode
         * @param theZipcode as a String
         * @return the the check digit or -1 for error
        public int calculateCheckDigitFromZipcode(String theZipcode) {}
         * Calculate the check digit from the barcode
         * @param theZipcode as a String
         * @return the the check digit or -1 for error
        public int calculateCheckDigitFromBarcode(String theBarcode) {}
         * Validate the format of the barcode.
         * Should be 6 blocks of 5 symbols each.
         * Also check if frame bars are present and strip them.
         * @param theBarcode
         * @return true for proper format, false for improper format
        public boolean validateBarcodeFormat (String theBarcode){}
        private  ArrayList<String> barcodeUnits = new ArrayList<String>();
    }

    These are just my two cents. The various methods that determine whether something is a zip or bar code can easily remain static. After all, you probably don't want to create an instance and then call something like isValid(), although you could do so. The various other methods could easily be instance methods. You could have a toZipCode() or toBarCode() method in each object to convert from one to the other. I would personally throw something like ValidationException rather than returning -1 for your various check-digit methods.
    - Saish

  • BufferedReader bf;       is this also treated as instance variable?

    hi i m just now finished my assignment and doing documentation
    and i got a single line here
    BufferedReader bf; //instance variable
    constructor{
    bf = new BufferedReader(new InputStreamReader(System.in));
    }and now i m doing documentation suddenly i got confused whether i should
    write this as instance variable or not. should i?? or shouldn't i
    i think this is obejct,,,,,,,but..i think it is instance variable as well..coz
    it is located in the class scope..confusing.....
    or not..

    hi i m just now finished my assignment and doing
    documentation
    and i got a single line here
    BufferedReader bf; //instance variable
    constructor{
    bf = new BufferedReader(new
    w InputStreamReader(System.in));
    }and now i m doing documentation suddenly i got
    confused whether i should
    write this as instance variable or not. should i?? or
    shouldn't i
    i think this is obejct,,,,,,,but..i think it is
    instance variable as well..coz
    it is located in the class scope..confusing.....
    or not..Okay, first of all constructor {} isn't valid Java syntax, I'm assuming you just used it for brevity. Second, yes bf is an instance variable because it's not a) static (class-) variable or b) local variable.
    If you thought instance variables refer only to primitives (int, byte etc.) you're wrong. Object references can also be instance variables.
    So yes, it is both an object reference and an instance variable.
    Sincerely,
    Jussi

  • Parsing XML and Storing values in instance variable

    hi,
    i'm new to XML.
    here i'm trying to parse an XML and store their element data to the instance variable.
    in my main method i'm tried to print the instance variable. but it shows "" (ie it print nothing ).
    i know the reason, its becas of the the endElement() event generated and it invokes the characters() and assigns "" to the instance variable.
    my main perspective is to store the element data in instance variable.
    thanks in advance.
    praks
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class mysax extends DefaultHandler
         String ctelement;
         CharArrayWriter contents;
         String vname1,vrcbreg1,vaddress1,vcountry1,vtelephone1,vfax1;
         String vname,vrcbreg,vaddress,vcountry,vtelephone,vfax;
         public mysax()
              vname1 = null;
              vrcbreg1 = null;
              vaddress1 = null;
              vcountry1 = null;
              vtelephone1 = null;
              vfax1 = null;
              contents= new CharArrayWriter();
         public void doparse(String url) throws Exception
              SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    ParserAdapter pa = new ParserAdapter(sp.getParser());
    pa.setContentHandler(this);
    pa.parse(url);          
         public void startElement(String namespace,String localName,String qName,Attributes atts)
              ctelement = localName;     
         public void endElement(String uri,String localName,String qName) throws SAXException
         public void characters(char[] ch,int start, int length) throws SAXException
              try
                   if(ctelement.equals("name"))
                        vname = new String (ch,start,length);
                        System.out.println("The method "+vname1);
              }catch (Exception e)
                   System.out.println("The exception "+e);
         public static void main(String args[])
              try
              mysax ms = new mysax();
              ms.doparse(args[0]);
              System.out.println("the contents name "+ms.vname1);
              catch(Exception e)
                   System.out.println("this is exception at main" +e);
    my XML looks like
    <coyprofile_result>
    <company>     
    <name>abcTech</name>
    <rcbreg>123456789</rcbreg>
    <address>Singapore</address>
    <country>sg</country>
    <telephone>123456</telephone>
    <fax>123155</fax>
    </company>
    </coyprofile_result>

    I believe that the problem has to do with the value you assign to ctelement. You are assigning the value of localName to ctElement, however for the element: <name>...</name> the localname is empty string i.e. "", but qName equals "name". Because you are assigning empty string to ctElement, when you do the comparison in characters of ctElement to "name" it will always be false. So in startElement change it to ctElement = qName; Try it and see if it works. I have produced similar programs and it works for me.
    Hope this helps.

  • Servlet instance variables

    This might be a dumb question, but I'll ask it anyway...
    I have methods in my servlet to handle registration, specifically creating address, customer and order objects.
    All the information needed for creating my objects is coming from the registration form.
    Right now if I were to call the createAddress() method, I have to pass the request object.... createAddress(request);
    Would it be "thread safe" to make an instance variable of the request and refer to it using getters/setters? Or would it be wiser (and best practice) to make instance variables for the request attributes (like firstName, lastName, etc.)? Or am I way off and shouldn't be doing any of the above?
    Thanks for the help.

    GB_java_guy wrote:
    To answer you question, I think it's different, from what I've read, because request attributes are supposed to be thread safe and I'd be using the request attributes instead of the request object.You said something about "making instance variables for the request attributes." I don't know what you mean by that, but if it's instance variable in the servlet class, don't do it.
    I have no clue what you mean by "request attirbutes intead of request object."
    So are you saying I should just use the request object and pass that to my methods instead? In general, yes. In some cases you may want to pass individual pieces of it--e.g. if there's a method that doesn't need to know or care about the fact that you're operating in a servlet context, and just needs a couple values to do its job.

  • Instance variables in Servlets.

    Hi
    Is it a good practice to use instance variable in servlet.
    Please refer code snippet below.
    public class ExcelAction extends HttpServlet {
    private int var1 =0;
    doGet () {
    var1++;
    fun1();
    fun1 (){
    var1++;
    }Like in above code I have used an instance variable var1 because I wish the same to be accessible in all servlet functions.
    I guess it is not a good practice, as different requests to this servlet at same time will result in multiple threads of this servlet. Which will make the state of var1 unsafe.
    If this is correct then what are the alternates if I wish to share variables between functions in a servlet.
    Thanks

    money321 wrote:
    Because in beginning I was not sure that Servlets instances are also actually threads.They are not not threads. Each call to doGet(), doPost() etc is called in a Thread and since there can be many simultaneous calls each having it's own thread a Servlet has to be thread safe.
    My other question was specific to threads as I was trying to implement threads.Why?
    >
    But in this one I rather used servlets.
    But apologies, as instance of servlet are also threads.As I said, they are not threads.
    >
    But still one last doubt.
    Sabre if you could please clarify the same as well :How about you do some reading [http://java.sun.com/developer/onlineTraining/Servlets/Fundamentals/|http://java.sun.com/developer/onlineTraining/Servlets/Fundamentals/] and use Google.
    >
    in your option 2 and three I will have to pass request object to function fun().No. You will need access to the request object for 2 and the servlet context for 3. You need to pass something
    If i am correct on this then is this too a better approach ?My preferred approach is 1 since it makes much of your code testable outside of a Servlet.

  • Scope of instance variables in servlets..

    Hi all,
              Sorry for asking a dumb question..
              What is the scope of instance variables in a servlet? Is the scope is
              limited to thread?
              In other words, in the following example, i am setting "testStr", in one
              request and when i tried to access the same instance variable from another
              request, i am getting it as null. Does it mean instance variable is limited
              to that particular thread/request?
              thanks in advance..
              -ramu
              

    Oops ... I had misunderstood and had the problem backwards ;-)
              > Is it known behavior? With registered servlet its working fine (a
              > instance variable is shared by all requests)
              I believe so; I typically deploy in a WAR so have not seen the problem that
              you describe. Servlets can be reloaded, so what you saw could have been
              caused bye a date/time mismatch between the .class file and the server's
              current time. On the other hand, that could be how WebLogic works.
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com
              +1.617.623.5782
              WebLogic Consulting Available
              "Ramu" <[email protected]> wrote in message
              news:[email protected]...
              > Hi Purdy,
              >
              > I got it. I am testing the servlet as a unregistered servlet, which is
              > creating instance for every new request!!!, which created this whole
              > confusion. Is it known behavior? With registered servlet its working fine
              (a
              > instance variable is shared by all requests)
              >
              > > What theory? ;-) Instance variables are on the object, and the object
              can
              > > be used by multiple threads, thus allowing multiple threads to access
              the
              > > same instance variables.
              > what i mean by theory here is, all instance variables in servlet should
              be
              > shared by all requests. Now i got it sir.
              >
              > Thank you..
              > -ramu
              >
              >
              > >
              > > Peace,
              > >
              > > --
              > > Cameron Purdy
              > > Tangosol, Inc.
              > > http://www.tangosol.com
              > > +1.617.623.5782
              > > WebLogic Consulting Available
              > >
              > >
              > > "Ramu" <[email protected]> wrote in message
              > > news:[email protected]...
              > > > Hi,
              > > >
              > > > > No, an instance variable in a servlet class is not limited to a
              > thread.
              > > > There
              > > > > is exactly one copy of the servlet created in memory and all
              requests
              > > pass
              > > > > through the same instance, thus sharing any instance variables. A
              > > couple
              > > > of
              > > > > things to remember:
              > > > I totally agree with you, But i am wondering why my sample servlet(i
              am
              > > > attaching the file) is not sharing the instance variables across
              > > > threads/reqs. (in 1st request set some string to "testStr" instance
              > > > variable, in next request if you read the same instance variable, you
              > will
              > > > get null!!)
              > > > Our current code is having instance variables. But right now we are
              not
              > > > getting any problems. But as per theory, instance variables should be
              > > shared
              > > > across threads/requests..
              > > >
              > > > Any how we are changing our code to remove all instance variables.
              > > >
              > > > thanks,
              > > > -ramu
              > > >
              > > > >
              > > > > 1.) Using instance or class variables in servlets that are not
              > read-only
              > > > is not
              > > > > a good thing to do. This makes the servlet not thread-safe. To
              > > maintain
              > > > > variables across requests, sessions, etc., use the servlet-defined
              > > objects
              > > > to
              > > > > store the state (e.g., request, session, etc.).
              > > > >
              > > > > 2.) If you modify the servlet class on disk, WebLogic will reload
              the
              > > > servlet
              > > > > class thus discarding the old instance and creating a new one (of
              > > course,
              > > > this
              > > > > depends on some configuration parameters for servlet reloading).
              > > > >
              > > > > Hope this helps,
              > > > > Robert
              > > > >
              > > > > Ramu wrote:
              > > > >
              > > > > > Hi,
              > > > > > thanks for quick reply.
              > > > > > I am not at all using SingleThreadModel. See the following code.
              > > > > > In first request i am passing "abc" value to testStr. But in
              second
              > > > request,
              > > > > > I am getting null for testStr in second request. It looks like
              (for
              > > me)
              > > > for
              > > > > > non single threaded model also, scope of instance variables is
              > > limited
              > > > to
              > > > > > Thread/Request.. But as per theory, because its not single
              threaded
              > > > model,
              > > > > > only one instance should be there AND testStr(instace variables)
              > > should
              > > > be
              > > > > > shared across the all threads. But i am not able see that
              behaviour
              > > > here.
              > > > > > But if declare instance variable as static, o am able to share
              it
              > > > across
              > > > > > all threads/requests.
              > > > > >
              > > > > > note:
              > > > > > From browser i am setting testStr to "abc" with URL like
              > > > > > "localhost/test1?testStr=abc"
              > > > > > And 2nd req from browser is like "localhost/test1" (on server
              > output
              > > i
              > > > am
              > > > > > getting null for testStr)
              > > > > >
              > > > > > Any ideas?
              > > > > >
              > > > > > thanks,
              > > > > > -ravi
              > > > > >
              > > > > > import java.io.*;
              > > > > > import javax.servlet.*;
              > > > > > import javax.servlet.http.*;
              > > > > >
              > > > > > public class test1 extends HttpServlet
              > > > > > {
              > > > > > public String testStr;
              > > > > >
              > > > > > public void doGet (HttpServletRequest req, HttpServletResponse
              res)
              > > > > > throws ServletException, IOException
              > > > > > {
              > > > > > doPost(req, res);
              > > > > > }
              > > > > >
              > > > > > public void doPost (HttpServletRequest req,
              HttpServletResponse
              > > res)
              > > > > > throws ServletException, IOException
              > > > > > {
              > > > > > try {
              > > > > > res.setContentType("text/html");
              > > > > > PrintWriter out = res.getWriter();
              > > > > > if(req.getParameter("testStr") != null)
              > > > > > {
              > > > > > testStr = req.getParameter("testStr");
              > > > > > System.out.println("set testStr = " + testStr);
              > > > > > }
              > > > > > else{
              > > > > > System.out.println("get testStr = " + testStr);
              > > > > > }
              > > > > >
              > > > > > }
              > > > > > catch(Exception e){
              > > > > > e.printStackTrace();
              > > > > > }
              > > > > >
              > > > > > }
              > > > > > }
              > > > > >
              > > > > > "Cameron Purdy" <[email protected]> wrote in message
              > > > > > news:[email protected]...
              > > > > > > Yes or no, depending on if your servlet implements
              > > SingleThreadModel.
              > > > > > >
              > > > > > > See the servlet 2.2 spec for documentation on how many instances
              > of
              > > a
              > > > > > > servlet will be created. See the doc for the SingleThreadModel
              > > > interface.
              > > > > > >
              > > > > > > Peace,
              > > > > > >
              > > > > > > --
              > > > > > > Cameron Purdy
              > > > > > > Tangosol, Inc.
              > > > > > > http://www.tangosol.com
              > > > > > > +1.617.623.5782
              > > > > > > WebLogic Consulting Available
              > > > > > >
              > > > > > >
              > > > > > > "Ramu" <[email protected]> wrote in message
              > > > > > > news:[email protected]...
              > > > > > > > Hi all,
              > > > > > > >
              > > > > > > > Sorry for asking a dumb question..
              > > > > > > >
              > > > > > > > What is the scope of instance variables in a servlet? Is the
              > scope
              > > > is
              > > > > > > > limited to thread?
              > > > > > > >
              > > > > > > > In other words, in the following example, i am setting
              > "testStr",
              > > in
              > > > one
              > > > > > > > request and when i tried to access the same instance variable
              > from
              > > > > > another
              > > > > > > > request, i am getting it as null. Does it mean instance
              variable
              > > is
              > > > > > > limited
              > > > > > > > to that particular thread/request?
              > > > > > > >
              > > > > > > > thanks in advance..
              > > > > > > >
              > > > > > > > -ramu
              > > > > > > >
              > > > > > > >
              > > > > > > >
              > > > > > >
              > > > > > >
              > > > >
              > > >
              > > >
              > > >
              > >
              > >
              >
              >
              

  • How to change value of instance variable and local variable at run time?

    As we can change value at run time using debug mode of Eclipse. I want to do this by using a standalone prgram from where I can change the value of a variable at runtime.
    Suppose I have a class, say employee like -
    class employee {
    public String name;
    employee(String name){
    this.name = name;
    public int showSalary(){
    int salary = 10000;
    return salary;
    public String showName()
    return name;
    i want to change the value of instance variable "name" and local variable "salary" from a stand alone program?
    My standalone program will not use employee class; i mean not creating any instance or extending it. This is being used by any other calss in project.
    Can someone tell me how to change these value?
    Please help
    Regards,
    Sujeet Sharma

    This is the tutorial You should interest in. According to 'name' field of the class, it's value can be change with reflection. I'm not sure if local variable ('salary') can be changed - rather not.

  • JSP and Instance Variables

    I have some questions about JSP presentation (Interactive Component Call in Screenflow):
    - Only BPM Objects are possible to be mapped in JSP?
    - Is possible to map two or more BPM Objects to the JSP?
    - What is the difference of mapping using the variable "attributes" in argument mapping and the option "Select BPM object variable" in main task of Interactive Component Call activity?

    I seem to be having a similar problem.
    If I include this fragment, for an instance variable called "contacts" which is a BPMObject of type "ITSSContactRequest".
    <%
    Object r = request.getAttribute("contacts");               
    Class cl = r.getClass();
    out.println(cl.getName());
    %>
    I get the following output:
    xobject.ITSSContactManagement.ITSSContactRequest
    and I can access the object via reflection:
    <%
    Object r = request.getAttribute("contacts");               
    Class cl = r.getClass();
    out.println(cl.getName());     
    Method getGeneralContacts = cl.getMethod("getGeneralContacts", null);               
    Object rv = getGeneralContacts.invoke(r);
    %>
    and access the rv variable accordingly.
    However, if I try and cast the variable directly:
    <%
    Object r = request.getAttribute("contacts");
    Class cl = r.getClass();               
    out.println(cl.getName());
    xobject.ITSSContactManagement.ITSSContactRequest rq = (xobject.ITSSContactManagement.ITSSContactRequest)r;
    %>
    I get the following error message:
    "The task could not be successfully executed. Reason: 'fuego.web.execution.exception.InternalForwardException: UnExpected error during internal forward process.'.
    See log file for more information [Error code: workspace-1258985548580] "
    The same error occurs if I try and import the object via
    <%@ page import="xobject.ITSSContactManagement.ITSSContactRequest" %>
    Thanks for any help.

  • About "method", "instance variable" and "constructor"

    Does a method need to be initialise?? if yes, how to write the code?
    for example,is it:
    public String mymethod( String args[]); ?
    public double mymethod2 (); ?
    what is the meaning of "instance variable" and "constructor"?
    Please help.....THANKS!

    Previously posted to this OP:
    Read the Java Tutorial: Learning the Java Language.
    http://java.sun.com/docs/books/tutorial/java/index.html
    � {�                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Migration from VIRSA 4.0 to GRC 10.0 (ARA)

    Hi Guys, We've just migrated from VIRSA 4.0 to GRC 10.0. We have only two connectors configured ECC and Finace System. Rules have been generated and we're using the standard "global" ruleset. The rules seem to be generated successfully ( I've checked

  • How to import actions from CS3 to CS4?

    I had a folder full of self-created actions in CS3. Now that I've installed CS4 I see they did not make the transition during install. How do I get them imported into CS4? I can't seem to find them in any Library folders, nor can I get CS3 to run any

  • Enhancement request: Namespace for Javascript

    Carl: As APEX market penetration grows and it matures as a web development environment, we will start to see APEX applications integrate one (or more) of the fantastic Javascript toolkits out there to build rich client-side functionality. To avoid co

  • Re: Display comma in a amount value.

    Hi experts, My requirement is i want to to display the comma in amount fields in script. i was declared one internal table with 5 fields , in that 3 fields are amount fields , these 3 fields also i was declared as type char, because i have to do some

  • XI to R/3 via ABAP Proxy

    Hi,    The Scenario is File to R/3 . The complete connection has established between XI and R/3 . The file is not transferred to the R/3 system . The SXMB_MONI shows the error as follows <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SO