This Java code defines a class with a main method that creates multiple threads. The threads increment and decrement shared static variables inside a synchronized block to prevent concurrent access, demonstrating thread synchronization.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views
Mutual Exclusion
This Java code defines a class with a main method that creates multiple threads. The threads increment and decrement shared static variables inside a synchronized block to prevent concurrent access, demonstrating thread synchronization.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
import java.lang.
*;
public class ATEST16 {
public final static int NUMTHREADS = 3; public static int sharedData = 0; public static int sharedData2 = 0; /* Any real java object or array would suit for synchronization */ /* We invent one here since we have two unique data items to synchronize */ /* An in this simple example, they're not in an object */ static class theLock extends Object { } static public theLock lockObject = new theLock();