p. 525 예제
package threadex;
import java.awt.Toolkit;
// 520 페이지
public class Thread01 {
public static void main(String[] args) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
for (int i = 0; i < 5; i++) {
toolkit.beep();
}
}
}
=> for문으로 돌리면 5번 출력되지만 실행은 1번(그 안에서 5회 도는거)
package threadex;
import java.awt.Toolkit;
// 520 페이지
public class Thread01 {
public static void main(String[] args) throws InterruptedException {
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.beep();
Thread.sleep(5000); // 1초
toolkit.beep();
Thread.sleep(5000); // 1초
toolkit.beep();
Thread.sleep(5000); // 1초
toolkit.beep();
Thread.sleep(5000); // 1초
toolkit.beep();
}
}
=> 5초에 한번씩 실행됨
package threadex;
import java.awt.Toolkit;
// 520 페이지
public class Thread01 {
public static void main(String[] args) throws InterruptedException {
Toolkit toolkit = Toolkit.getDefaultToolkit();
for (int i = 0; i < 5; i++) {
toolkit.beep();
Thread.sleep(3000); // 1초
}
}
}
=> 3초에 한번씩 5회실행
'국비과정 > JAVA' 카테고리의 다른 글
20230629 _[20일차]_02. HeidiSQL _ 테이블생성 & 데이터입력 (0) | 2023.06.29 |
---|---|
20230629 _[20일차]_01. 스레드 + 동기화 (0) | 2023.06.29 |
20230628 _[19일차]_02. Excel을 자바로 (0) | 2023.06.28 |
20230628 _[19일차]_01. 보조스트림 (0) | 2023.06.28 |
20230626 _[17일차]_02. HTML_게시판 만들기 (0) | 2023.06.26 |