Skip to content

Instantly share code, notes, and snippets.

@frekele
Created October 20, 2019 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frekele/e450918db9b2394465d6a37cc23b2c66 to your computer and use it in GitHub Desktop.
Save frekele/e450918db9b2394465d6a37cc23b2c66 to your computer and use it in GitHub Desktop.
ThreadDemo02.java
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);
}
}
}
}
@frekele
Copy link
Author

frekele commented Oct 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment