Por
Saiyine
el 2007-07-05 02:46:04 - Secciones: - Enlace permanente: 782
Within Java, there are three main ways you can execute background threads: to inherit from the Thread class, to implement the Runnable interface and the TimerTask object.
This second example shows the second way, which is implementing the Runnable interface, that is almost identical to inheriting from Thread. What's its use, then? Easy, Java doesn't support multiple inheritance, so if we only had the Thread way we would be stuck without being able of accessing others classes in this way. So here comes implementing the Runnable interface, wich allows us inheriting from wichever class we want AND running the class in the background if we want to.
The code is fairly easy, and very similar to the Thread's. See that we use implementand not extends when declaring the class.
public class ThreadSample implements RunnableOtras entradas de la web que podrian interesarte:
. . .
. . .
. . .
. . .
Se suspenden las traducciones de la wikipedia hasta que no se aclaren las condiciones de su adquisición práctica por parte de google.
. . .
Página web ©2001-2010 Saiyine generada en s, con 4639631 visitas en total, hoy (de un total de 0 previstas).
. . .