Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cargasincronica;
- public class CargaHilosParametros {
- public static void main(String[] args) {
- HiloCargaArchivo imagen = new HiloCargaArchivo("fondo.jpg", "Imagen", 1500);
- HiloCargaArchivo video = new HiloCargaArchivo("intro.mp4", "Video", 4000);
- HiloCargaArchivo audio = new HiloCargaArchivo("musica.mp3", "Audio", 2000);
- imagen.start();
- System.out.println("Llamado carga fondo.jpg");
- video.start();
- System.out.println("Llamado carga intro.mp4");
- audio.start();
- System.out.println("Llamado carga musica.mp3");
- }
- }
- class HiloCargaArchivo extends Thread {
- private String nombreArchivo;
- private String tipoArchivo;
- private int tiempoCarga; // tiempo simulado en milisegundos
- public HiloCargaArchivo(String nombre, String tipo, int tiempo) {
- this.nombreArchivo = nombre;
- this.tipoArchivo = tipo;
- this.tiempoCarga = tiempo;
- setName(tipo + " - " + nombre); // Asigna nombre al hilo
- }
- @Override
- public void run() {
- System.out.println(getName() + ": iniciando carga...");
- try {
- Thread.sleep(tiempoCarga);
- } catch (InterruptedException e) {
- System.out.println(getName() + ": error en carga");
- }
- System.out.println(getName() + ": carga completada");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement