Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 27, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/13b84e06773bb2c9d2820c7df59ea3f7 to your computer and use it in GitHub Desktop.
Save parzibyte/13b84e06773bb2c9d2820c7df59ea3f7 to your computer and use it in GitHub Desktop.
Runnable runnable = new Runnable() {
@Override
public void run() {
// Esto se ejecuta en segundo plano una única vez
while (true) {
// Pero usamos un truco y hacemos un ciclo infinito
try {
// En él, hacemos que el hilo duerma
Thread.sleep(1000);
// Y después realizamos las operaciones
System.out.println("Me imprimo cada segundo");
// Así, se da la impresión de que se ejecuta cada cierto tiempo
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment