As a senior engineer, you sometimes are thrown into a situation, where you have to come up with some ways to improve the performance of your server side java multithreaded application.
The code was written over a span of 6-7 years and you have only a vague idea of what it does and does not do. More importantly it uses java language features that are old. What do you do?
Before kicking up a profiler and doing memory/CPU profiling - there is something very easy you can do which does not involve all that, provided you can move to Java 5.
There are a number of new classes and frameworks in Java 5 which should improve the performance and reduce the boilerplate code you need to write for a multithreaded application.
Here are some of them.
- Replace synchronized collections from your old code with new concurrent collections.i.e. of you have a synchronized HashMap - replace it with ConcurrentHashMap. The Concurrent classes in Java 5 perform fine grained locking and hence provide better scalability.
- Identify places where you use Java list class with Queue semantics and replace it with the Java Queue class , introduced in version 5 or 6. Java Queue class is much more efficient than the List class, whose interface supports random access.
- Use Blocking Queue (or Bounded Blocking queue), whenever possible.
- A common pattern in multithreaded Java applications, is the thread pool along with a work queue. See if you can use Java 5 Executor Task Execution framework.
I will keep posting some more patterns to emulate as I come across more of them.
2 comments:
nice post..thanq
Interesting to know.
Post a Comment