Advertisement
Sothian

checkifcompleted

Nov 6th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public class Main {
  2. public static void main(String[] argv)throws Exception {
  3. Thread thread = new MyThread();
  4. thread.start();
  5.  
  6. if (thread.isAlive()) {
  7. System.out.println("Thread has not finished");
  8. } else {
  9. System.out.println("Finished");
  10. }
  11. long delayMillis = 5000;
  12. thread.join(delayMillis);
  13.  
  14. if (thread.isAlive()) {
  15. System.out.println("thread has not finished");
  16. } else {
  17. System.out.println("Finished");
  18. }
  19. thread.join();
  20. }
  21. }
  22. class MyThread extends Thread {
  23. boolean stop = false;
  24. public void run() {
  25. while (true) {
  26. if (stop) {
  27. return;
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement