Java Reference
In-Depth Information
can use the techniques in this chapter wherever round-tripping is a concern
and the back-end services lend themselves to caching architectures.
Vignette's fast portal solutions
Vignette takes caching a step further: it offers highly personalized content-
management solutions for the development of portals and other Internet soft-
ware. With the Vignette system, templates (using JSP s and JSP fragments)
make it possible to publish dynamic content. The architecture performs well,
partially because of a good caching solution. A template manager helps to
maintain a template cache and flushes an entry whenever a template is added,
deleted, or modified. An additional manager, the Docroot Manager, works
with the web server to ensure that outdated files are completely purged from
the server's document root. This combination makes it easy for the web server
and application server to work together and maintain an efficient and effective
cache, with little management overhead for the user. You can read more about
these content-management solutions at http: // www.vignette.com.
5.4
Cache-related mini-antipatterns
By far the biggest problem related to caches is the failure to use one where
appropriate. We should be aware of a few additional issues as we implement
caches. Within Java, two common antipatterns are related to concurrent pro-
gramming. In addition, we need to carefully manage our memory: we
should have a firm strategy for removing stale elements from the cache, and
for capping the size, or at least doing some garbage collection if memory
becomes constrained.
5.4.1
Concurrent access to static cache
Trying to access static class-level variables concurrently is a common problem.
We must synchronize access to these variables in order to make them thread-
safe. You can't have more than one instance writing to the hash table at the
same time and expect correct results. Note that synchronizing on the method
level won't work unless the method is static, because although there could be
several commands, there's only one hash table. Synchronizing at the method
level will merely prevent several threads in the same instance from using the
same method concurrently. The synchronize keyword will lock only a single
object. Since all of the execute methods in our command objects could try to
concurrently access our boardCache object, we need to lock it with a critical
section. By synchronizing on the boardCache object, we ensure that all threads
Search WWH ::




Custom Search