MINIMIZING SYNCHRONIZATION OVERHEAD ACROSS CLASSES OR METHODS Synchronization is key to writing well-behaved multithreaded applications in Java. Synchronization prevents multiple threads from entering code sections or accessing variables simultaneously. However, synchronization also introduces a fair amount of overhead, dragging down the performance of your application. By using lock objects created solely for the purpose of synchronization, you can provide arbitrarily fine-grained control over how multiple threads access your code, thereby reducing the overhead of thread-safe programming. For example, suppose you want to synchronize code across multiple methods, or even multiple classes. For multiple methods in a single class, you can synchronize on the entire class or instance, but that can introduce a lot of unnecessary overhead. Synchronizing across multiple classes is impossible using the standard methods without creating some kind of proxy class to control access. The most efficient way to handle either case is to introduce an Object instance used solely for the purpose of synchronization. First, you need to create the object, usually as a static variable accessible from the affected code: static final public Object lockObject = new Object(); Now you can synchronize on that object anywhere you need. Here's an example using two methods that would work equally well if the methods were in different classes as long as the lockObject instance was accessible to both:void method1() { synchronized(lockObject) { //protected code } } void method2() { synchronized(lockObject) { //protected code } } You can use both methods with the assurance that the protected code in each method will never execute at the same time as any other code protected by the lockObject instance. By taking advantage of the ability to synchronize on any arbitrary object, you can achieve the flexibility and efficiency needed to create high-performance multithreaded Java applications.------------------------------------------