Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > What problems will raise when a servlet invoke a static method inother class?

Reply
Thread Tools

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

 
 
Alex Luya
Guest
Posts: n/a
 
      08-09-2009
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!
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      08-09-2009
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
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      08-10-2009
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
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      08-10-2009
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.)


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      08-11-2009
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-11-2009
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.
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      08-12-2009
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
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      08-12-2009
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.)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Python packaging tools to maintain source distributions inother languages? eric.lemings@gmail.com Python 3 07-25-2012 01:39 AM
Raise X or Raise X()? bvdp Python 10 03-12-2012 04:08 PM
"raise (type, value, traceback)" and "raise type, value, traceback" Jack Bates Python 0 05-02-2011 05:23 PM
raise Exception or raise Exception() ernest Python 2 11-14-2010 08:14 PM
raise or not to raise [Newbie] Jacol Python 5 02-05-2007 11:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57