본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

(105)
FileInputStream / FileOutputStream / FileReader / FileWriter FileInputStream / FileOutputStream / FileReader / FileWriter 출력 cf.객체 생성만 이름 변경해주면 똑같다. import java.io.*; // FileCopyTest.java ==> copy.txt // a.txt b.txt ==> a.txt 입력 파일 없다. 오류 발생. // src/FileCopyTest.java copy.txt => copy.txt // src/JoinTest.java copy.txt => 기존 내용은 삭제된다. // true로 소스 변경한 후에 // src/FileCopyTest.java copy.txt => 기존 내용 유지 출력. public class FileCopyTest { public static void main(Str..
thread 예제 2 package thread; // SharedCellSync.java public class SharedCellSync { public static void main(String args[]) { holdInteger h = new holdInteger(); produceInteger p = new produceInteger(h); consumeInteger c = new consumeInteger(h); p.start(); c.start(); } } class produceInteger extends Thread { private holdInteger pHold; public produceInteger(holdInteger h) { pHold = h; } public void run() { for (i..
wait(), notify() wait(), notify() 예제 class Account { String name; int total; public Account(String name) { this.name = name; } // 순서 스레드 접근 영역 : 동기화 영역. synchronized void deposit(int money, String loc) { if(total>7000){ try { System.out.println("최대 잔액 초과"); wait(); // wait 스레드 실행시작 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } total = 0; notify(); // notify 스레드 실행..
synchronized 연습 thread 연습 class Account { String name; int total; public Account(String name) { this.name = name; } // 순서 스레드 접근 영역 : 동기화 영역. synchronized void deposit(int money, String loc) { total += money; try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(loc+money+total); } int getTotal() { return total; } } class Bank e..
Join Join 예제 class Test extends Thread{ int i=1; public void run(){ try { sleep(5000); // 5초 일시중지 } catch (InterruptedException e) { e.printStackTrace(); } i=10; System.out.println("run : "+i); } } public class JoinTest { public static void main(String[] args) throws InterruptedException { Test t = new Test(); // 실행상태 ; main 생성상태 t.start(); // 대기상태 ; t 실행상태 ; main // run 수행 완료 i 값: t 수행 t.join(); // ..
Runnable Runnable 생성, 변환, 출력 // 1. 멀티 스레드 동작 클래스 정의 class SimpleThread2 implements Runnable{ String msg; // ??? public SimpleThread2(String msg) { this.msg = msg; } // 1-2. run overriding // st1 시작, st2 시작 동시에 실행, 두개 멀티스레드 객체 생성 public void run(){ for(int i=1;i
스레드(Thread) Thread 예제 class SimpleThread extends Thread{ String msg; public SimpleThread(String msg) { this.msg = msg; } public void run(){ for(int i=1;i
Java 문제 7 CompareUtil 클래스의 void compareList (ArrayList first, ArrayList second) 메소드를 완성하십시오. compareList 메소드는 ArrayList 타입의 객체 2개를 입력받아 저장 데이터를 하나씩 비교하고 차이가 있는 경우에만 HashMap에 저장하여 리턴합니다. class CompareUtilMain { main 적절히 구현 } > No 첫번째 ArrayList 내용 두번째 ArrayList 내용 결과값(HashMap) 1 Learn to build powerful Enterprise Java applications using the Spring Framework. Learn To Build Powerful Enterprise Java applicati..

반응형

⚠️ 광고 차단 프로그램 감지

애드블록, 유니콘 등 광고 차단 확장 프로그램을 해제하거나
화이트리스트에 추가해주세요.