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

A

Alex Luya

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!
 
L

Lew

Alex 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?

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).
 
A

Arne Vajhøj

Alex 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?

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

If it is not it will not.

Arne
 
M

Mike Schilling

Arne said:
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.)
 
A

Arne Vajhøj

Mike said:
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
 
R

Roedy Green

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

Arne Vajhøj

Roedy said:
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
 
M

Mike Schilling

Arne said:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top