RUNNING BACKGROUND CODE IN JAVA WITH THREADS - .: .: Saiyine :. :.

Running background code in Java with Threads

Por Saiyine Enviar correo el 2007-07-03 03:22:42 - Secciones:  JAVA ENGLISH  - Enlace permanente: 779

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 first example shows how to use the inheritance of the Thread class. Copy-paste it into your editor of choice and check how easy is to create alternative threads to your program main's. Look how the threads concurrency makes the threads output get mixed at the console: probably it'll become more aparent by increasing the top of the for.

public class ThreadEjemplo extends Thread
{
    
    public ThreadEjemplo(String str)
    {
        super(str);
    }
    
    public void run()
    {
        for (int i = 0; i < 100 ; i++)
            System.out.println(getName());
        System.out.println("Fin " + getName());
    }
    
    public static void main (String [] args)
    {
        new ThreadEjemplo("A").start();
        new ThreadEjemplo("B").start();
        new ThreadEjemplo("C").start();
        new ThreadEjemplo("D").start();
    }
}

Otras entradas de la web que podrian interesarte:

o o o o 


Tu nombre (Nick):

Tu correo (Email):
  Necesario para tu gravatar!

Tu página (URL):

Escribe aqui tu comentario:

       :noworry: :roll: :huh: :push: :OO 8) 8O :( :) :? :D :P :o :x :| ;) ^^ xD



Vista previa activada.

Vista previa (6/6/6, 6:66)


Fondos de pantalla

. . .

Recomendamos


. . .

Descargas

  • ApagaPC
    apagapc241.exe  (4339)
  • LimpiaDocus
    LimpiaDocus001.exe  (3627)
  • RCM
    rcm001.zip  (3062)
  • Popmail
    popmail-0.4-psmn.tar.gz  (3132)
  • Manual de Delphi en PDF
    delphi_pdf.zip  (3764)
  • Evangelio del Perl
    Evangelio_del_perl.pdf  (3786)
  • Excel Simpsons
    Excel Simpsons  (3789)
  • . . .

    Proyectos Online

  • Saiyine Store
  • Kunowalls!!!
  • Fondos de pantalla
  • Picaday: imagenes sexys o chocantes.
  • Scarlett: fotos de Scarlett Johansson
  • WhatsmyIP: obtener tu IP pública
  • Uma Thurman: galeria de Uma Thurman
  • FunPics: imagenes graciosas
  • . . .

    Blogs

  • Por lo que más querais, no entreis a estos: Tapanez, Yhandros, Onez.

  • Otros en español: El Mundo Today, La libreta de Van Gaal, Chavalina, Kirai, Mundo Geek, Microsiervos.

  • Mis lecturas en guiri: Michael Yon, Coding Horror, YCombinator news, MySQL Performance, Slashdot.

    . . .
  • Utilidades

  •  Coral  (1583), cacheando webs
  •  Spam.la  (1899), correo de usar y tirar
  •  Mailinator  (1802), correo de usar y tirar
  •  Bug me not  (1580), absurdos registros di NO
  •  Trashmail  (1629), correo de usar y tirar

    . . .

  • Página web ©2001-2011 Saiyine descargada en s, con 5908343 visitas en total, hoy (de un total de 0 previstas).

    . . .