Vinh La Kiến

43 bundles
1 file13 days ago
2

Java Thread/Runable

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748package com.company;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

class DownloadRunable implements Runnable {

    public int data;

    @Override
    public void run() {
        while(data < 1000) {
            System.out.println("class DownloaderThread extends Thread: " + ++data);
        }
    }
}

class DownloadThread extends Thread {

    public int data;

    @Override
    public void run() {
        super.run();
        
        while(data < 1000) {
            System.out.println("class DownloaderThread extends Thread: " + ++data);
        }
    }
}

public class Main {

    public static void main(String[] args) throws FileNotFoundException {
        DownloadRunable download = new DownloadRunable();
        download.data = 0;
        
        DownloadThread downloadThread = new DownloadThread();

        Thread thread = new Thread(download);
        thread.start();

        int i = 0;
        while(i < 1000) {
            System.out.println("public static void main(String[] args): " + ++i);
        }
    }
}