Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 비밀번호변경
- emmet환경설정
- 페이지 재사용
- github
- Git
- redirect
- 로그아웃
- forward
- 인코딩
- 비밀번호암호화
- mvc
- 입력메소드
- 별찍기
- 회원탈퇴
- 국민취업지원제도
- 검색기능
- 관리자회원조회
- 페이징
- jdbc설정
- jdbc환경설정
- jsp기본
- 내배카
- 정처기
- 내일배움카드
- 회원정보수정
- 국취제
- live server 환경설정
- 권한변경
- 배열
- 국비학원
Archives
- Today
- Total
기록
*26일차 실습 본문
[Thread 실습문제]
<문제 1>
- 실행용클래스 com.thread.sleep.SleepTest
+ sendAphorism() : void
- 좋아하는 속담, 경구 10개를 문자열배열에 담고, 3초마다 랜덤하게 출력하세요.
- 10번 출력후 종료하세요.
package com.thread.sleep;
public class SleepTest implements Runnable{
@Override
public void run() {
String[] strarr =new String[10];
strarr[0] = "Regret for wasted time is more wasted time";
strarr[1] = "connecting the dots";
strarr[2] = "Love yourself.";
strarr[3] = "Seize the day";
strarr[4] = "Don't dwell on the past";
strarr[5] = "Where there is a will there is a way";
strarr[6] = "Be brave";
strarr[7] = "Live positive";
strarr[8] = "why not me";
strarr[9] = "Life is all about timing";
for(int i=1 ; i<10 ;i++) {
System.out.println(strarr[i]);
try {
Thread.sleep(3000);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}
------------------------------
package com.thread.sleep;
public class Run {
public static void main(String[] args) {
new Thread(new SleepTest()).start();
System.out.println("[" + Thread.currentThread().getName()+"종료 !]");
}
// public void printTest() {
// new Thread(new SleepTest()).start();
//
// }
}
<문제 2>
- 실행용 클래스 : com.thread.alphabet.AlphabetTest.java
- 쓰레드 클래스 : com.thread.alphabet.UpperAlphbetThread.java
com.thread.alphabet.LowerAlphbetThread.java
두개의 멀티쓰레드를 만들고, 각각 알파벳대문자, 알파벳 소문자를 출력하세요.
package com.thread.alphabet;
public class AlphabetTest {
public static void main(String[] args) {
Thread th1 = new Thread(new UpperAlphabetThread(),"대문자");
Thread th2 = new Thread(new LowerAlphabetThread(),"소문자");
th1.start();
th2.start();
}
}
----------------------------------------
package com.thread.alphabet;
public class UpperAlphabetThread implements Runnable{
@Override
public void run() {
System.out.println("[대문자 출력]");
for(char ch='A' ; ch<='Z';ch++) {
System.out.println(ch);
}
}
}
----------------------------------------
package com.thread.alphabet;
public class LowerAlphabetThread implements Runnable {
@Override
public void run() {
System.out.println("[소문자 출력]");
for(char ch='a' ; ch<='z';ch++) {
System.out.println(ch);
}
}
}
'학원 > 실습' 카테고리의 다른 글
*35일차 실습 (0) | 2022.03.28 |
---|---|
*34일차 실습 (0) | 2022.03.28 |
*25일차 실습 (0) | 2022.02.28 |
*24일차 ncs (수강생 평가) -실기 (0) | 2022.02.25 |
*24일차 ncs (수강생 평가) -필기 (0) | 2022.02.25 |