I am not too familiar with Java. I have the following question. I have seen similar posts on SO on this. What I am asking may be a bit different.
If I have the following situation
public class A {
public static void myMethod () {
// Does a whole lot of things including calls to DB
}
}
vs
public class A {
public void myMethod () {
// Does a whole lot of things including calls to DB
}
}
// In some other class
public void caller () {
A.myMethod (); vs new A().myMethod();
}
Reason I am looking at the non-static method is to ensure data is not shared between instances.
If the caller () method is being called often, would there be a performance cost because of the instantiation/class loading followed by the call to non-static method?
A myDB = new A();, and then#callercan domyDB.myMethod();. The number of instances made is relatively trivial compared to the IO expense of the DB operations. Overall though, I'd question what state is really being shared between instances ofAsuch that they would even need separation. Be wary of some of the design pitfalls as well with baking in all of your DB operations into a static utility class