O'Reilly logo

C# for Java Developers by Adam Freeman, Allen Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Synchronization

The basic synchronization support in .NET is similar to that in Java. For advanced functionality, .NET goes into areas not covered by Java, exposing some sophisticated tools and fine-grain controls.

Basic Locking

In Java, the keyword synchronized is used to ensure that only one thread will enter a specific section of code at a time. In the following example, Java ensures that a thread will not enter the code block containing the comment until an exclusive lock has been obtained on the this object.

public void doSomething() {
    synchronized (this) {
        // some synchronized operation
    }
}

When the thread exits the code section, Java will automatically release the lock so that another thread can attempt to acquire it and enter the synchronized ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required