https://www.techiedelight.com/ko/atomicinteger-class-java/
Java의 AtomicInteger 클래스
이 게시물은 AtomicInteger 여러 스레드에서 동시에 액세스할 수 있는 다중 스레드 환경에서 원자 정수 카운터로 사용할 수 있는 Java의 클래스입니다. 카운터를 증가시키는 것은 Java에서 스레드로부
www.techiedelight.com
package com.company.design.aop;
import com.company.design.proxy.Html;
import com.company.design.proxy.iBrowser;
public class AopBrowser implements iBrowser {
~~~~
private Runnable before; <<<< <<<<
private Runnable after; <<<< <<<<
public AopBrowser(String url, Runnable before, Runnable after){
this.url = url;
this.before = before; <<<< <<<< <<<<
this.after = after; <<<< <<<<
}
@Override
public Html show() {
before.run(); <<<< <<<< run했을때 뭐할지 구현은 실구현시 람다식으로
if(html == null){
~~
try {
Thread.sleep(1500); >> 이건 시간너무빠를거같아서 일부러 늘리기용
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
after.run(); <<<< <<<<
System.out.println("AopBrowser html cache : " + url);
return html;
}
}
import com.company.design.aop.AopBrowser;
import com.company.design.proxy.BrowserProxy;
import com.company.design.proxy.iBrowser;
import java.util.concurrent.atomic.AtomicLong;
public class Main {
public static void main(String[] args) {
//시간체크 동시성문제로 Atomic을 쓴다함
AtomicLong start = new AtomicLong(); <<<< <<<<
AtomicLong end = new AtomicLong(); <<<< <<<<
iBrowser aopBrowser = new AopBrowser("www.naver.com",
()-> { <<<< 람다식으로 구현함
System.out.println("before");
start.set(System.currentTimeMillis()); <<<< <<<<
},
()->{
long now = System.currentTimeMillis();
end.set(now - start.get()); <<<< <<<<
}
);
aopBrowser.show();
System.out.println("loading time: " + end.get());
aopBrowser.show();
System.out.println("loading time: " + end.get());
}
}
ch3. 웹개발 개론 (0) | 2022.07.28 |
---|---|
ch2.6 옵저버, 2.7 파사드, 2.8 전략 패턴 (0) | 2022.07.28 |
ch2.4프록시패턴 & ch2.5 데코레이터 패턴 (0) | 2022.07.27 |
ch2.2 싱글톤패턴 && 2.3 어댑터 패턴 (0) | 2022.07.27 |
ch2. 디자인 패턴 (0) | 2022.07.26 |
댓글 영역