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. Advertising

  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. Advertising

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. Laurent Beaubier \(free.fr\)

    HttpServlet implementation in Tomcat 4.1

    Laurent Beaubier \(free.fr\), Jul 3, 2003, in forum: Java
    Replies:
    1
    Views:
    773
    Sudsy
    Jul 3, 2003
  2. brijesh

    HTTPSERVLET

    brijesh, Jul 31, 2003, in forum: Java
    Replies:
    1
    Views:
    3,342
    Kim Andreassen
    Jul 31, 2003
  3. Raoul Markus

    parameter in HttpServlet.doGet

    Raoul Markus, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    685
    Raoul Markus
    Aug 21, 2003
  4. news.amnet.net.au
    Replies:
    1
    Views:
    924
    Sudsy
    Sep 15, 2004
  5. Marko Langbein

    Tomcat and HTTPServlet destroy Problem

    Marko Langbein, Jun 17, 2005, in forum: Java
    Replies:
    5
    Views:
    4,181
    Alan Krueger
    Jun 21, 2005
Loading...

Share This Page