我想知道从构造函数本身调用阻塞方法是否是一个坏主意。
我很想知道在这种情况下我们是否有任何指导方针/规则,我们不应该在构造函数中调用阻塞方法。
基本上我正在尝试这样做:
class A
{
// Many instance variables that is to be initialized on instantiaion
String tempVar = null;
public A()
{
// Initialize all the instance variables
tempVar=objectClassB.**callBlockingMethod**(); // this method call would return
// some data from ClassB Object
}
public static void main(String args ...)
{
A a = new A();
// Or should I call the blocking method call only after instantiation according
// to any guidelines of Java pertaining to performance ?
// IMPORTANT: It's only when the blocked method returns value , should the main
// thread proceed as the object 'a' would be sent for further processing
}
}
PS:呃,如果我的问题听起来很基本,我很抱歉。