It’s not uncommon to write data to the database and the filesystem in the same transaction. The challenge is to remove files from the filesystem when the transaction fails. It is possible to combine database Spring transactions with files on the filesystem .
The following example has a Spring-managed transactional method which will first write some data to the database. After doing so it will create a file on the filesystem.
Clean the Spring Context between tests
When running a JUnit test with the SpringJUnit4ClassRunner the Spring context is specified with the ContextConfiguration annotation.
|
|
Creating a Spring Context takes some time depending on the size of the application and the classpath that needs to be scanned. Therefore a Context will be stored in the Spring Context cache so that it can be reused for a different test-case.
Sometimes however your tests will change some values in the Spring Context which may cause other tests to fail. The solution is to clean the Spring Context between tests. This can be done with the DirtiesContext annotation.
Getting rid of 'Tomcat did not stop in time.' messages.
The larger your Servlet application becomes the more time it needs to start. The same thing happens with the time it takes to stop an application.
By default a Tomcat server gives an application 5 seconds to terminate before the “Tomcat did not stop in time. PID file was not removed.” messages is logged. 5 seconds isn’t a lot of time, especially when the application needs to close a connection pool or perform some cleanup tasks.
Hibernate FetchMode explained by example
During quite a few projects I’ve ran into issues with the performance of fetching collections in Hibernate. In most cases these performance problems could be fixed by switching from the default fetching strategy to a more suitable alternative. To explain the different ways of fetching collections I’ve created an ‘explained by example’ guide. For those not familiar with the subject it could provide a good place to start tweaking Hibernate performance.
Connect to JMX(MBeans) on Tomcat behind a firewall
I recently had to configure a Tomcat to allow remote access to the JMX service. It involved some configuration to get a connection through the firewall so I’ve made a configuration-guide for those interested.