Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. package com.company.demo3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. class Processor extends Thread {
  6. private volatile boolean running = true;
  7.  
  8. public void run() {
  9. while (running) {
  10. System.out.println("hi");
  11.  
  12. try {
  13. Thread.sleep(100);
  14. } catch (InterruptedException e) {
  15. e.printStackTrace();
  16. }
  17. }
  18. }
  19.  
  20. public void shutdown() {
  21. running = false;
  22. }
  23. }
  24.  
  25. public class App {
  26.  
  27. public static void main(String[] args) {
  28. Processor p = new Processor();
  29. p.start();
  30.  
  31. System.out.println("Press Enter to stop...");
  32. Scanner scanner = new Scanner(System.in);
  33. scanner.nextLine();
  34.  
  35. p.shutdown();
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement