Created
October 20, 2019 05:45
-
-
Save frekele/e450918db9b2394465d6a37cc23b2c66 to your computer and use it in GitHub Desktop.
ThreadDemo02.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
public class Main { | |
public static void main(String[] args) { | |
for (int i = 1; i < 11; i++) | |
new MyThread("Multiples of " + i, i, i * 10).start(); | |
} | |
} | |
class MyThread extends Thread { | |
private String name; | |
private int multiples, maximum; | |
public MyThread(String name, int multiplo, int maximum) { | |
this.name = name; | |
this.multiples = multiplo; | |
this.maximum = maximum; | |
} | |
@Override | |
public void run() { | |
for (int i = multiples; i <= maximum; i += multiples) { | |
System.out.println(name + ": " + i); | |
try { | |
Thread.sleep(100); | |
} catch (InterruptedException ex) { | |
Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Online java compiler: