Grundlagen der Programmierung 2 SS 2005 - Datei Increaser.java
public class Increaser
{
private int n = 0;
public void increase()
{
int tmp = n;
System.out.println("Increasing to " + (n+1));
n = tmp+1;
}
public static void main(String[] args)
{
int limit = 500;
Increaser inc = new Increaser();
IncreaserThread incThread[] = new IncreaserThread[3];
incThread[0] = new IncreaserThread(limit,inc);
incThread[1] = new IncreaserThread(limit,inc);
incThread[2] = new IncreaserThread(limit,inc);
incThread[0].start();
incThread[1].start();
incThread[2].start();
}
}
class IncreaserThread extends Thread
{
private int limit;
private Increaser inc;
public IncreaserThread(int limit, Increaser inc)
{
this.limit = limit;
this.inc = inc;
}
public void run()
{
for (int i=0; i<limit; i++)
{
inc.increase();
}
}
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 20.05.2005


