public synchronized void playMusicA(){
        for(int i = 0; i < 10; i ++){
            System.out.println("신나는 음악!!!");
            try {
                Thread.sleep((int)(Math.random() * 1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }// for}//playMusicA
  1. 효과

    1. 메소드가 모두 실행된 후 다음 메소드가 실행됨
  2. 종료

    1. 메소드 실행 종료
    2. wait() 메소드
  3. 활용

    1. 마지막 대기 쓰레드의 지연시간을 줄이기 위해 문제가 있는 부분만 synchronized 블록을 사용
     public void playMusicB(){
            for(int i = 0; i < 10; i ++){
                synchronized(this){
                    System.out.println("슬픈 음악!!!");
                }
                try {
                    Thread.sleep((int)(Math.random() * 1000));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }// for}//playMusicB
    

    synchronized(this){ . . . };