Consider the below struts Action class in which, I am using a StringBuilder variable inside the execute method. My question: Is the variable sb threadsafe or not?
public DemoAction extends Action
{
......
public ActionForward execute(.....)
{
StringBuilder sb = new StringBuilder();
}
}
What if the same variable sb declared outside the execute(). Remember there will be only one object for DemoAction in WebContainer.?
Local variables are thread safe, as long as no other thread somehow gets a reference to the same string builder instance, it’s thread safe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With