3

I have the following question:

if inside doPost method of a servet i create some local variables and pass them to static method of another class which use them and returns something...what happens when multiple thread access the doPost method, create local variables and pass thouse variables to the static method?

Is it thread safe?

Joro Seksa
  • 1,525
  • 3
  • 18
  • 44
  • IF the passing value is Object based and the static method does not keep the reference in a static variable, so it's thread safe –  Jul 05 '13 at 06:01

1 Answers1

4

Parameters are passed, and local variable created, on the stack, of which every thread has its own. So they are threadsafe.

Of course, the objects they point to may be shared and pose thread synchronization issues.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • 3
    assuming ofcourse that the static method itself is threadsafe and doesnt use any static variables or stupid unsynchronized static objects. – Markus Mikkolainen Jul 05 '13 at 00:14
  • This might be interesting for you: http://stackoverflow.com/questions/616601/is-httpsession-thread-safe-are-set-get-attribute-thread-safe-operations – mmirwaldt Jul 05 '13 at 00:28