Question: I don't understand why using timer variable like this in the following codes.

Question 1: In both startTimer() and stopTimer(), there is a local variable aTimer to be used before the operation on timer, what is the intention?

Question 2: In stopTimer(), timer will be assigned null, so if timer is not null which means this timer is already created, when startTimer() is called, timer will not be created again. Is this best practice to check whether timer is running or not? By assign null to timer, PMD also reports violation on "NullAssignment"

```
private Timer timer;

private void startTimer() {
  if (timer == null) {
    Timer aTimer = timerFactory.createTimer(100000, null);
    aTimer.setListener(this);
    timer = aTimer;
  }
}

private void stopTimer() {
  if (timer != null) {
    Timer aTimer = timer;
    timer = null;
    aTimer.cancel();
    aTimer.setListener(null);
 }
}

public void start() {
  synchronized(..) {
     startTimer();
  }
}

public void stop() {
 synchronized(..) {
     stopTimer();
 }
}

```

Answer: 
Your code is equivalent to:

```
private boolean started = false;
private Timer timer;

public synchronized void start() {
    if (!started) {
        timer = timerFactory.createTimer(100000, null);
        timer.setListener(this);
        started = true;
    }
}

public synchronized void stop() {
    if (started) {
        timer.cancel();
        timer.setListener(null);
        started = false;
    }
}

```

which is shorter and easier to understand (IMHO). The local variable is superfluous since your code is synchronized and your `timer` variable can't be accessed by two threads concurrently.

And using the fact that `timer` is `null` as a flag for started/not started is fine with such a short code but as more lines get added, it will become confusing. I prefer a proper `started` flag which is self-explanatory.
My assumption is the original author of this object wanted to encapsulate the Timer object so that you couldn't by mistake recreate it inbetween start() and stop().

This has no directly added value but perhaps if working with a large team of people on a frequently used object it's to prevent unwanted access to messing the information up, or something.