thread-safe stopwatch API
I am wondering how to write a thread-safe stopwatch. Below is a simple stopwatch implementation, and it provide basic operations of a stopwatch, but it is not thread-safe.

Now, all that I can think about is to add synchronize to each methods (start(), lap(), stop(), reset()). Is there exist some other way to achieve thread-safety on the stopwatch? 

    import java.util.List;
    import java.util.concurrent.CopyOnWriteArrayList;

    public class Stopwatch {
        private long startTime;
        private long endTime;
        private boolean isRunning;

        // lapTimes is able to record all the lap time.
        private CopyOnWriteArrayList<Long> lapTimes;
  
        Stopwatch() {
            isRunning = false;
            lapTimes = new CopyOnWriteArrayList<Long>();
        }
  
        public void start() {
            if (!isRunning) {
                isRunning = true;
                startTime = System.currentTimeMillis();
            } else {
                throw new IllegalStateException("cannot start when running!");
            }
        }
  
        public void lap() {
            if (isRunning) {
                endTime = System.currentTimeMillis();
                lapTimes.add(endTime - startTime);
                startTime = endTime;
            } else {
                throw new IllegalStateException("cannot lap when not running!!");
            }
        }
  
        public void stop() {
            if (isRunning) {
                endTime = System.currentTimeMillis();
                lapTimes.add(endTime - startTime);
                isRunning = false;
            } else {
                throw new IllegalStateException("cannot stop when not running!");
            }
        }
  
        public void reset() {
            isRunning = false;
            lapTimes.clear();
        }
  
        public List<Long> getLapTime() {
            return lapTimes;
        }
}

thread-safe stopwatch API
===

I am wondering how to write a thread-safe stopwatch. Below is a simple stopwatch implementation, and it provide basic operations of a stopwatch, but it is not thread-safe.

Now, all that I can think about is to add synchronize to each methods (start(), lap(), stop(), reset()). Is there exist some other way to achieve thread-safety on the stopwatch? 

    import java.util.List;
    import java.util.concurrent.CopyOnWriteArrayList;

    public class Stopwatch {
        private long startTime;
        private long endTime;
        private boolean isRunning;

        // lapTimes is able to record all the lap time.
        private CopyOnWriteArrayList<Long> lapTimes;
  
        Stopwatch() {
            isRunning = false;
            lapTimes = new CopyOnWriteArrayList<Long>();
        }
  
        public void start() {
            if (!isRunning) {
                isRunning = true;
                startTime = System.currentTimeMillis();
            } else {
                throw new IllegalStateException("cannot start when running!");
            }
        }
  
        public void lap() {
            if (isRunning) {
                endTime = System.currentTimeMillis();
                lapTimes.add(endTime - startTime);
                startTime = endTime;
            } else {
                throw new IllegalStateException("cannot lap when not running!!");
            }
        }
  
        public void stop() {
            if (isRunning) {
                endTime = System.currentTimeMillis();
                lapTimes.add(endTime - startTime);
                isRunning = false;
            } else {
                throw new IllegalStateException("cannot stop when not running!");
            }
        }
  
        public void reset() {
            isRunning = false;
            lapTimes.clear();
        }
  
        public List<Long> getLapTime() {
            return lapTimes;
        }
}
