Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java static method and thread safety

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?

like image 546
Joro Seksa Avatar asked Dec 03 '25 06:12

Joro Seksa


1 Answers

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.

like image 162
Thilo Avatar answered Dec 05 '25 23:12

Thilo