3 ms·
The main problem with Java is that you rely heavily on libraries and frameworks which may or may not enable you to apply a desired pattern. Recent example: I a
by chopin 9y ago
The main problem with Java is that you rely heavily on libraries and frameworks which may or may not enable you to apply a desired pattern.
Recent example: I am using Tomcat as a servlet engine. For dependency injection I am using JNDI. Tomcat can be configured to call a provided ObjectFactory to generate JNDI objects when they are requested. The environment I am using allows for some kind of blue-green deployment, I can switch between different fired up virtual machines transparently to users. I use this when upgrading. My provided Objectfactory logs when objects are created (some of them should be strictly singletons). Sometimes the logs indicated that multiple objects where created after switching to the newly updated machine. This was due to a high load on the system in which multiple threads where busy with incoming requests simultaneously. Neither the language library nor Tomcat has any safeguards in place (synchronization of any sort) although JNDI and in particular Tomcat supports singleton creation. I had to resort to statically creating the required instances at loading the Objectfactory, a pattern I dislike with a passion (you can't swap the implementation during runtime which can be annyoing in any long-running environment).
- peterashford 9y agoTo be fair, that's more an issue of using a framework than anything to do with Java.