/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * eine einfache Unterklasse * von Thread */ //-------------------- public class SimpleThread extends Thread { //-------------------- public SimpleThread(String name) { super(name); } //-------------------- public void run() { for (int i = 1; i <= 10; ++i ) { System.out.println(getName() + " the " + i + ". time"); doSomething(); } System.out.println(getName() + " finished"); } //-------------------- public void doSomething() { try { // really doing something ??? // simulate some complex computations sleep( (int)(Math.random() * 500) ); } catch ( InterruptedException e ) { } } }