Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ContohThread {
- public static void main(String[] args){
- ThreadA a = new ThreadA();
- ThreadB b = new ThreadB();
- b.start();
- a.start();
- }
- }
- class ThreadA extends Thread{
- public void run(){
- synchronized(this){
- for(int i=1; i<=100 ; i++){
- System.out.println(i);
- try{
- Thread.sleep(1000);
- }catch(Exception e){
- }
- }
- }
- }
- }
- class ThreadB extends Thread{
- Scanner in = new Scanner(System.in);
- public void run(){
- synchronized(this){
- while(!in.hasNextLine());
- System.out.println("ada enter");
- System.out.println("Press enter to continue");
- in.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement