If I make a class with only methods and no variables, with each method having its own local variable then, will that class be thread-safe? for eg.
public class Client {
public String xyz(final String inputXML) {
DataInputStream dis = null;
DataOutputStream dout = null;
Socket clientSocket = null;
//do some processing
}
public String abc(final String inputXML) {
DataInputStream dis = null;
DataOutputStream dout = null;
Socket clientSocket = null;
//do some processing
}
}
now if I launch multiple threads of this Client then, will the class be thread safe ?
Yes your class is thread safe.
A method is thread safe if:
Your methods haven't access to shared variables so are 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