public static synchronized int myCounter = 0; // Does NOT workA. Use AtomicInteger or AtomicLong like this:
public static AtomicInteger = new AtomicInteger(0);This can safely be accessed from multiple threads.
public static synchronized int myCounter = 0; // Does NOT workA. Use AtomicInteger or AtomicLong like this:
public static AtomicInteger = new AtomicInteger(0);This can safely be accessed from multiple threads.