Results 1 to 3 of 3

Thread: Thread Safety for Servlets

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Thread Safety for Servlets

    I'm writing a servlet and I need to ensure it is thread safe.

    How can I do that?

    Thanks!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No generic way. Think about resources that one thread might access while another is modifying them. Make no assumptions about the order in which things happen. Then insert synchronization where necessary.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Yes CornedBee is right. There is really no generic way to write multithreaded code that trys to tap single resource. What you want to be careful of though is miss-synchronization or deadlock.

    But, synchronization is not always the best possible soultion to the problem of inconsistent behavior as a result of thread scheduling. One technique used ensure thread safety is to use local variables instead of fields wherever possible since they do not have synchronization problems. Every time a method is entered the JVM creates a completely new set of local variables. The variables are destroyed when the method exits. This means that there is no possible way for a local variable to be used in teo different threads. Every thread has its own set of local variables.

Posting Permissions

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



Click Here to Expand Forum to Full Width