Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package threadtointerrupt;
- import java.lang.Thread.State;
- import java.util.Random;
- /**
- *
- * @author Philipp Johann Fritz
- */
- public class ThreadToInterrupt extends Thread {
- private char ch;
- @Override
- public void run() {
- while (!this.isInterrupted()) {
- ch = (char) (64 + new Random().nextInt(26));
- System.out.println("Thread: " + ch);
- }
- System.out.println("Thread wurde unterbrochen!!!");
- }
- public char getch() {
- return ch;
- }
- }
- class TreadInterrupt {
- public static void main(String[] args) {
- ThreadToInterrupt t = new ThreadToInterrupt();
- t.start();
- while (t.getch() != 'A') {
- }
- t.interrupt();
- for (int i=0; i<=100; i++) {
- System.out.println(t.getState());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment