What problems will raise when a servlet invoke a static method inother class?

Discussion in 'Java' started by Alex Luya, Aug 9, 2009.

  1. Alex Luya

    Alex Luya Guest

    I know the servlet is multithread,So the question is:
    1,will this cause inconsistence when a multithread class invoke a
    sigle thread class?
    2,if not,will this will cause performance bottle neck,any suggestions
    to solove this issue?
    Thank you!
     
    Alex Luya, Aug 9, 2009
    #1
    1. Advertising

  2. Alex Luya

    Lew Guest

    Re: What problems will raise when a servlet invoke a static methodin other class?

    Alex Luya wrote:
    > I know the servlet is multithread,So the question is:
    > 1,will this cause inconsistence when a multithread class invoke a
    > sigle thread class?
    > 2,if not,will this will cause performance bottle neck,any suggestions
    > to solove this issue?


    Regarding "What problems will raise when a servlet invoke a static method in
    other class?"

    The problems, if any, are the same as when any instance calls a static method,
    in its own class or any other.

    If the method is thread safe, you're fine. If not, you need to add
    synchronization of one kind or another (java.util.concurrent structure,
    'synchronized' code block, Lock, or 'volatile' variable).

    --
    Lew
     
    Lew, Aug 9, 2009
    #2
    1. Advertising

  3. Alex Luya

    Arne Vajhøj Guest

    Re: What problems will raise when a servlet invoke a static methodin other class?

    Alex Luya wrote:
    > I know the servlet is multithread,So the question is:
    > 1,will this cause inconsistence when a multithread class invoke a
    > sigle thread class?
    > 2,if not,will this will cause performance bottle neck,any suggestions
    > to solove this issue?


    If the static method is thread safe, then it will work in multithreaded
    environment.

    If it is not it will not.

    Arne
     
    Arne Vajhøj, Aug 10, 2009
    #3
  4. Re: What problems will raise when a servlet invoke a static method in other class?

    Arne Vajhøj wrote:
    > Alex Luya wrote:
    >> I know the servlet is multithread,So the question is:
    >> 1,will this cause inconsistence when a multithread class invoke a
    >> sigle thread class?
    >> 2,if not,will this will cause performance bottle neck,any
    >> suggestions
    >> to solove this issue?

    >
    > If the static method is thread safe, then it will work in
    > multithreaded environment.
    >
    > If it is not it will not.


    And if it's made thread-safe by taking a lock for a long period,
    performance will suffer. (Suffer badly if the container runs out of
    worker threads.)
     
    Mike Schilling, Aug 10, 2009
    #4
  5. Alex Luya

    Arne Vajhøj Guest

    Re: What problems will raise when a servlet invoke a static methodin other class?

    Mike Schilling wrote:
    > Arne Vajhøj wrote:
    >> Alex Luya wrote:
    >>> I know the servlet is multithread,So the question is:
    >>> 1,will this cause inconsistence when a multithread class invoke a
    >>> sigle thread class?
    >>> 2,if not,will this will cause performance bottle neck,any
    >>> suggestions
    >>> to solove this issue?

    >> If the static method is thread safe, then it will work in
    >> multithreaded environment.
    >>
    >> If it is not it will not.

    >
    > And if it's made thread-safe by taking a lock for a long period,
    > performance will suffer. (Suffer badly if the container runs out of
    > worker threads.)


    Yep.

    But the main point is that servlets is not that special
    regarding this.

    Arne
     
    Arne Vajhøj, Aug 11, 2009
    #5
  6. Alex Luya

    Roedy Green Guest

    Re: What problems will raise when a servlet invoke a static method in other class?

    On Sat, 8 Aug 2009 20:05:00 -0700 (PDT), Alex Luya
    <> wrote, quoted or indirectly quoted someone
    who said :

    >I know the servlet is multithread,So the question is:
    >1,will this cause inconsistence when a multithread class invoke a
    >sigle thread class?
    >2,if not,will this will cause performance bottle neck,any suggestions
    >to solove this issue?


    Either a method is thread safe or it is not. The staticness makes it
    slightly more vulnerable, but the problem is essentially the same.

    see http://mindprod.com/jgloss/threadsafe.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    "You can have quality software, or you can have pointer arithmetic; but you cannot have both at the same time."
    ~ Bertrand Meyer (born: 1950 age: 59) 1989, creator of design by contract and the Eiffel language.
     
    Roedy Green, Aug 11, 2009
    #6
  7. Alex Luya

    Arne Vajhøj Guest

    Re: What problems will raise when a servlet invoke a static methodin other class?

    Roedy Green wrote:
    > On Sat, 8 Aug 2009 20:05:00 -0700 (PDT), Alex Luya
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >> I know the servlet is multithread,So the question is:
    >> 1,will this cause inconsistence when a multithread class invoke a
    >> sigle thread class?
    >> 2,if not,will this will cause performance bottle neck,any suggestions
    >> to solove this issue?

    >
    > Either a method is thread safe or it is not.


    Very few methods is threadsafe or not.

    Most methods are threadsafe in a given context and not in
    another context.

    Arne
     
    Arne Vajhøj, Aug 12, 2009
    #7
  8. Re: What problems will raise when a servlet invoke a static method in other class?

    Arne Vajhøj wrote:
    > Roedy Green wrote:
    >> On Sat, 8 Aug 2009 20:05:00 -0700 (PDT), Alex Luya
    >> <> wrote, quoted or indirectly quoted someone
    >> who said :
    >>> I know the servlet is multithread,So the question is:
    >>> 1,will this cause inconsistence when a multithread class invoke a
    >>> sigle thread class?
    >>> 2,if not,will this will cause performance bottle neck,any
    >>> suggestions to solove this issue?

    >>
    >> Either a method is thread safe or it is not.

    >
    > Very few methods is threadsafe or not.


    public static isFeatureImplemented(String featureName)
    {
    return false;
    }

    (I know, you said "few", not "none", but I couldn't resist.)
     
    Mike Schilling, Aug 12, 2009
    #8
    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. circuit_breaker
    Replies:
    2
    Views:
    2,046
    Jack Jia
    Apr 4, 2004
  2. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    417
    Gabriel Genellina
    Feb 5, 2007
  3. ernest
    Replies:
    2
    Views:
    298
    Roy Smith
    Nov 14, 2010
  4. Jack Bates
    Replies:
    0
    Views:
    285
    Jack Bates
    May 2, 2011
  5. Replies:
    3
    Views:
    235
Loading...

Share This Page