summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing2204.java
blob: 73189fd95fee0086a27743ca2358d669b02ebe7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Listing2204.java */

class A2204
{
  int irgendwas;
  //...
}

class B2204
extends A2204
implements Runnable
{
   public void run()
   {
      int i = 0;
      while (true) {
         if (Thread.interrupted()) {
            break;
         }
         System.out.println(i++);
      }
   }
}

public class Listing2204
{
   public static void main(String[] args)
   {
      B2204 b = new B2204();
      Thread t = new Thread(b);
      t.start();
      try {
         Thread.sleep(1000);
      } catch (InterruptedException e){
         //nichts
      }
      t.interrupt();
   }
}