I've been happily building/using my own basic framework based on the Front Contorller
pattern with Command and Controller strategy.
For DB actions, a Connection, which is gotten from a DataSource (pooled connections) is handed to each command that a factory creates, called within the Controller's service method. This seems safe and efficient to me as the connection is used only by that command's invocation, and it's serviced by its own
thread.
I've recently seen a similar Command/Controller framework a well-known book that actually creates a 'Connection' at
servlet init time in the Controller and then passes that same Connection to each command.
My question is this: Isn't that approach non thread-safe? The controller servlet's Connection instance can't be safely shared by multiple service threads.
What's nagging at me is that it appears to be such and obvious, fundamental problem that I'm wondering if I'm just missing the point - not the author.
Any insights?