Results 1 to 4 of 4
  1. #1
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Thumbs up Instance Variable In Servlet

    Can we have instance and static variable in Servlet.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Default

    Yes. The code is exactly the same as always. Try it, see what you get.

  3. #3
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    It Compiles. But In Running Environment Is There Any Problem?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Web Application Servers are threaded and normally operate as follows:

    1. The Web Container instantiates the servlet as soon as the application context is started (or, by some, as soon as the first request for it comes in).

    2. A request arrives for that servlet.

    3. The Web Container starts a thread with this already instantiated Servlet.

    As you can see from above, there is only one instance of this Servlet, regardless of the number of concurrent requests for it, so, the varying users using (and definately even worse changing) information in these instance variables will stepping all over each other, as they will all be using the same instance of the Servlet.

Similar Threads

  1. instance access
    By sujaiyer85 in forum Advanced Java
    Replies: 2
    Last Post: 04-23-2008, 07:37 AM
  2. Replies: 4
    Last Post: 11-05-2007, 05:14 PM
  3. New Instance for SWT
    By srinivasa_v in forum SWT / JFace
    Replies: 1
    Last Post: 08-08-2007, 01:02 AM
  4. Replies: 1
    Last Post: 08-07-2007, 03:47 PM
  5. Instance variable
    By Jack in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 04:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •