J
Josh
Google Groups -
I've read conflicting opinions on the use of static methods in DAO
objects. Proponents of the static approach state that you save memory
overhead by eliminating multiple instantiations. Proponents of
instantiate state that the Java DAO pattern indicates non-static
methods and that using static methods makes polymorphism impossible.
My question is this: if all of the DAO methods are static, what
happens when hundreds of simultaneous requests come in. Assuming that
the DAO's have no state, there isn't a possibility of data corruption
(i.e. it's thread safe). However, it seems like all of the threads
would have to shift back/forth for control of the method. Doesn't
this create a throughput bottleneck if every thread shares the same
method?
Maybe an example can better illustrate. Assume that 3 HTTP requests
have come in and each resulted in a call to retrieveRecord, each
passing it's own unique ID. If I understand correctly, all three
threads will be hitting the shared method at the same time. Though it
is "thread safe", won't each thread have to wait for the others to
stop using it until it can?
public SomeDAO {
public static Record retrieveRecord(int id) {
...
}
}
I'm pretty ignorant regarding multithreading, so this could be way
off, but in my mind, all incoming threads (e.g. from HTTP requests)
would share the same static method and couldn't all use it
simultaneously. I know that synchronizing a method definitely results
in this behavior - my question is, does declaring a method static have
a similar effect?
Thanks,
Josh
I've read conflicting opinions on the use of static methods in DAO
objects. Proponents of the static approach state that you save memory
overhead by eliminating multiple instantiations. Proponents of
instantiate state that the Java DAO pattern indicates non-static
methods and that using static methods makes polymorphism impossible.
My question is this: if all of the DAO methods are static, what
happens when hundreds of simultaneous requests come in. Assuming that
the DAO's have no state, there isn't a possibility of data corruption
(i.e. it's thread safe). However, it seems like all of the threads
would have to shift back/forth for control of the method. Doesn't
this create a throughput bottleneck if every thread shares the same
method?
Maybe an example can better illustrate. Assume that 3 HTTP requests
have come in and each resulted in a call to retrieveRecord, each
passing it's own unique ID. If I understand correctly, all three
threads will be hitting the shared method at the same time. Though it
is "thread safe", won't each thread have to wait for the others to
stop using it until it can?
public SomeDAO {
public static Record retrieveRecord(int id) {
...
}
}
I'm pretty ignorant regarding multithreading, so this could be way
off, but in my mind, all incoming threads (e.g. from HTTP requests)
would share the same static method and couldn't all use it
simultaneously. I know that synchronizing a method definitely results
in this behavior - my question is, does declaring a method static have
a similar effect?
Thanks,
Josh