Advertisement
heryvandoro

Untitled

Dec 11th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.*;
  2. public class ContohThread {
  3.  
  4. public static void main(String[] args){
  5. ThreadA a = new ThreadA();
  6. ThreadB b = new ThreadB();
  7. b.start();
  8. a.start();
  9. }
  10. }
  11.  
  12. class ThreadA extends Thread{
  13.  
  14. public void run(){
  15. synchronized(this){
  16. for(int i=1; i<=100 ; i++){
  17. System.out.println(i);
  18. try{
  19. Thread.sleep(1000);
  20. }catch(Exception e){
  21.  
  22. }
  23. }
  24. }
  25. }
  26. }
  27.  
  28. class ThreadB extends Thread{
  29. Scanner in = new Scanner(System.in);
  30. public void run(){
  31. synchronized(this){
  32. while(!in.hasNextLine());
  33. System.out.println("ada enter");
  34. System.out.println("Press enter to continue");
  35. in.nextLine();
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement