Java Runnable Thread Example

Para crear un thread en Java sin extender la clase Thread o implementar la clase Runnable.

El ejemplo es para hacer un delay de 2 segundos sin interrumpir la ejecución de la aplicación.

Thread ejemploThread = new Thread(new Runnable() {
  public void run() {
    try {
      Thread.sleep(2000);
      // Codigo a ejecutar despues del sleep

      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      // end loop
    }
  });
ejemploThread.start();

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>