Custom Java class blinking effect

I’m wondering what exact steps you would recommend if I want to make a Shape over a Piece blink for a few seconds.

What I can already do:
-Properly compile and add a decorator custom Java class to a Piece
-Access the Map in which this visual effect should happen
-Produce a proper Shape that has the position, size and orientation of the Piece
-Draw that shape with a transparent shade

What I can’t do yet:
-Start some kind of Thread or Executorservice that will draw that shape on and off for n times, and get acceptable levels of fluidity.

I solved it, I used a Timer():

final Timer timer = new Timer();
timer.schedule(new TimerTask() {
int count = 1;
public void run() {
//do stuff
//control how many times using the count variable
} catch (Exception e) {


to achieve the blink, I used an an anonymous class that implements Drawable,
in the draw function, I use a boolean toggle which alternates between:

  1. drawing the shape
  2. repainting the map

there are probably some optimisations to do, but I’m working on other more urgent things for my module and it’s good enough.
Sometimes, the last “flash” of my blink (which uses a transparent alpha colored shape) will stay drawn at the end of the cycle but will disappear if you move the mouse or click somewhere in the background of the Map.