HttpServlet and Static Methods

E

Eric

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

Anton Spaans

Eric said:
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.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top