HttpServlet and Static Methods

Discussion in 'Java' started by Eric, Feb 12, 2004.

  1. Eric

    Eric Guest

    I have a threadsafe servlet, but if I add a call to a Static method in
    another class, will my servlet still be threadsafe?

    I know if I Synchronize it, it will be, but I would rather not do such.

    Thank you in advance for any help.



    -Eric
     
    Eric, Feb 12, 2004
    #1
    1. Advertisements

  2. Eric

    Anton Spaans Guest

    "Eric" <> wrote in message
    news:%7RWb.11486$...
    > I have a threadsafe servlet, but if I add a call to a Static method in
    > another class, will my servlet still be threadsafe?
    >
    > I know if I Synchronize it, it will be, but I would rather not do such.
    >
    > Thank you in advance for any help.
    >
    >
    >
    > -Eric
    >
    >


    A quick answer. It depends on the implementation of that static method:

    If that static method accesses static data (either static data directly or
    cached instance-data) in a thread-unsafe way, then you can not call that
    method without sacrificing your own method's thread-safety.
    If that static method purely/only acts on the parameters you provide it when
    you call it (i.e. it uses only stack-variables and instances it creates
    while it's running), then there is no problem.

    So, look at the documentation of that static mehotd. If it claims to be
    thread-safe, no problem. If not so, call it at your own risk.. :)

    -- Anton Spaans.
     
    Anton Spaans, Feb 12, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo
    Replies:
    1
    Views:
    715
    Scott Allen
    Jan 7, 2005
  2. Laurent Beaubier \(free.fr\)

    HttpServlet implementation in Tomcat 4.1

    Laurent Beaubier \(free.fr\), Jul 3, 2003, in forum: Java
    Replies:
    1
    Views:
    872
    Sudsy
    Jul 3, 2003
  3. SaravanaKumar
    Replies:
    6
    Views:
    9,885
    Tony Morris
    Oct 19, 2004
  4. Marko Langbein

    Tomcat and HTTPServlet destroy Problem

    Marko Langbein, Jun 17, 2005, in forum: Java
    Replies:
    5
    Views:
    4,471
    Alan Krueger
    Jun 21, 2005
  5. Oliver Wong
    Replies:
    14
    Views:
    1,936
    Chris Uppal
    Jun 13, 2006
  6. lightning
    Replies:
    4
    Views:
    1,138
    Daniel Pitts
    Oct 30, 2008
  7. o_ssie
    Replies:
    0
    Views:
    431
    o_ssie
    Apr 9, 2009
  8. Kenneth McDonald
    Replies:
    5
    Views:
    635
    Kenneth McDonald
    Sep 26, 2008
Loading...