3
A simple Runnable
- public class SimpleRunnable implements Runnable {
- private String name;
- public SimpleRunnable(String s) {
- this.name = s;
- }
- public void run() {
- for (int i = 0; i < 10; i++) {
- System.out.println(i + " " + this.name + " - " + Thread.activeCount());
- try {
- Thread.sleep((long) (Math.random() * 1000));
- }
- catch (InterruptedException e) {
- }
- }
- System.out.println("DONE! " + this.name);
- }
- public static void main(String args[]) {
- (new Thread(new SimpleRunnable("sleepy"))).start();
- }
- }
$ javac SimpleRunnable.java
$ java SimpleRunnable
0 sleepy - 2
1 sleepy - 2
2 sleepy - 2
3 sleepy - 2
4 sleepy - 2
5 sleepy - 2
6 sleepy - 2
7 sleepy - 2
8 sleepy - 2
9 sleepy - 2
DONE! sleepy
Comments