https://my.jrebel.com/ 

위의 url 에 접속, 가입한다.




광고 수신, 이메일 수신을 동의하면 라이센스 키를 발급해준다. 전화번호도 적어야 한다.. (세상에 공짜는 없다)



JRebel 플러그인을 설치하고 Active 에 발급받은 라이센스를 입력하면 끝






'tomcat' 카테고리의 다른 글

Catalina.out 사용중지  (0) 2013.09.25
Tomcat. Catalina Log 기록하지 않기  (0) 2013.04.29
프로젝트 import 시 Tomcat Server Unbound 문제  (0) 2012.05.16
톰캣 7.0 server.xml  (0) 2012.04.05
publishing faild with multiple error.  (0) 2012.03.28


0. 구조
 - AbstractJavaSamplerClient 상속받은(extends) 클래스 를 기준으로 테스트 생성
 - SampleResult의 sampleStart() / sampleEnd() 메소드로 측정
 
1. 빌드
 1.1 프로젝트 우클릭 > Export > Runnable JAR file > Copy required libraries ~ 선택 > 생성

2. 배포
 2.1 생성된 라이브러리 폴더, jar 파일을 apache-jmeter-2.9\lib\ext\ 복사

3. 테스트
 3.1 jmeter.properties 수정 - 159 라인 remote_hosts= 수정 (원격으로 실행시킬 jmeter PC ip)
 3.2 jmeter-server.bat 실행
 3.3 jmeterw.cmd 실행(Master만)
 3.4 시작 및 모니터링


'java > test' 카테고리의 다른 글

GCM 테스트 쉘 스크립트  (0) 2014.05.12
jmeter 테스트 - JavaRequest, Remote Start  (0) 2013.04.15
jmeter 테스트 - 생성  (0) 2013.04.15
기본지식 :
equals 는 데이터 자체를 비교한다.
== 는 주소값을 비교한다.

즉 아래의 "hello" 같은 고정된 값을 연속적으로 비교했을때는 당연히 ==가 빠르다.
new String("hello") 으로 비교하면 의도치 않은 연산을 했을 것이다. 


결론 : 
==가 빠르다. 주소값 비교이므로 조심해서 사용하자.



출력값
Sample Count : 1000000
== is slow: 33077
equals is slow: 51856
same: 915067
Result : == is Win. 63.786254242517735 %



  1. public class CompareEqualsSpeed {
  2.     private void compareSpeed(int count) {
  3.         int countCompare = 0;
  4.         int countEquals = 0;
  5.         long start = 0;
  6.         long end = 0;
  7.         int same = 0;
  8.         if (count < 0) {
  9.             return;
  10.         }
  11.         for (int i = 0; i < count * 2;) {
  12.  
  13.             start = System.nanoTime();
  14.             if ("Hello" == "Hello") {
  15.                 i++;
  16.             }
  17.             end = System.nanoTime();
  18.             long compare = end - start;
  19.  
  20.             start = System.nanoTime();
  21.             if ("Hello".equals("Hello")) {
  22.                 i++;
  23.             }
  24.             end = System.nanoTime();
  25.             long equals = end - start;
  26.  
  27.  
  28.             if (compare > equals) {
  29.                 countCompare++;
  30.             } else if (equals > compare) {
  31.                 countEquals++;
  32.             } else {
  33.                 same++;
  34.             }
  35.         }
  36.  
  37.         System.out.println("Sample Count : " + count);
  38.         System.out.println("== is slow: " + countCompare);
  39.         System.out.println("equals is slow: " + countEquals);
  40.         System.out.println("same: " + same);
  41.  
  42.         String result = "Result : ";
  43.         System.out.println((countCompare < countEquals)
  44.                 ? (result += "== is Win. " + (double) ((double) countCompare / (double) countEquals) * 100) + " %"
  45.                 : (result += "equals is Win" + (double) ((double) countEquals / (double) countCompare) * 100) + " %");
  46.     }
  47.  
  48.     public static void main(String... args) {
  49.         CompareEqualsSpeed main = new CompareEqualsSpeed();
  50.         main.compareSpeed(1000000);
  51.     }
  52. }




Stream 

 - 병렬성 (parallel 연산자)을 가질 수 있다.

 - 병렬처리가 가능하므로 기존의 방법보다 빠르다.

 - stream 은 내부적으로 지연된 실행을 원칙으로 한다.

 -> 실제 연산을 하기 전 까지는 수행하지 않는다.

 -> 지연된 연산

 - 생성되는 모든 객체는 불변객체가 아니라 새로 생성해서 사용한다.

 - 병렬 객체의 이슈에 대해 대응이 가능하다.


  1. public class Ex4 {
  2.  
  3.         public static void main(String[] args) throws IOException {
  4.                 String contetns = new String(Files.readAllBytes(Paths.get("text.txt")), StandardCharsets.UTF_8);
  5.                 List<String> word = Arrays.asList(contetns.split("[\\P{L}}]+"));
  6.                
  7.                 int count = 0;
  8.                 for(String w : word) {
  9.                         if(w.length() > 10) {
  10.                                 count++;
  11.                         }
  12.                 }
  13.                
  14. //              long lc = word.stream().filter(w->w.length() > 10).count(); // 파이프라인을 통해 사용. C#LINQ
  15.                 long lc = word.parallelStream().filter(w->w.length() > 10).count(); // 파이프라인을 통해 사용. C#LINQ
  16.                 Stream<String> list =  word.stream().map(String::toLowerCase);
  17.                 Stream<Character> firstChar=  word.stream().map(->s.charAt(0));              
  18.                 System.out.println(count + lc);
  19.                 list.forEach(System.out::println);
  20.                 firstChar.forEach(System.out::println);
  21.         }
  22.  
  23. }


Default Method 와 추상 메소드와 다른점

 - 추상 클래스는 필드를 가질 수 있다.

 - 자식은 상속받은 필드를 사용 할 수 있다.


Deafult Method

 - 기본 연산자를 가질 수 있다.

 - static 표현 또 한 가능하다.

 


  1. interface IFoo {
  2.         void foo();
  3.         default void goo() { // 기본 연산자를 가질수 있다.
  4.                 // 추상클래스는 필드를 가질 수 있다. (자식이 상속받은 필드를 사용가능하다.)
  5.                 System.out.println("G");
  6.         }
  7.         static void sfoo() { // 정적 메소드 표현도 가능
  8.                 System.out.println("...");
  9.         }
  10. }
  11.  
  12. // Array, Arrays
  13. // Collection, Collections 정적 메소드 추가
  14.  
  15. class A implements IFoo { // goo와 sfoo를 사용가능
  16.  
  17.         @Override
  18.         public void foo() {
  19.                 System.out.println("A");
  20.         }
  21.  
  22. }
  23. class B implements IFoo {
  24.  
  25.         @Override
  26.         public void foo() {
  27.                 System.out.println("B");
  28.                
  29.         }
  30.        
  31. }
  32. public class Ex3 {
  33.  
  34.         public static void main(String[] args) {
  35.         }
  36.  
  37. }


Method Reference

 - 타입만 맞춰주면 내부적으로 연결된다.

인터페이스의 데이터 타입이 맞으면 동작을 보장.

ex)

btn.setListener(dialog::doOnClick); //  Method Reference - 타입만 맞춰주면 내부적으로 연결한다.

btn.setListener(System.out::println); 

Stream<Button1> stream = Arrays.stream(labels).map(Button1::new); // Construct Reference



  1. @FunctionalInterface
  2. interface IClickListener {
  3.         void onClick(String s);
  4. }
  5. class Button1 {
  6.         private List<IClickListener> listeners = new ArrayList<>();
  7.        
  8.         private String text;
  9.        
  10.         public Button1 (){}
  11.         public Button1(String s) {
  12.                 text = s;
  13.                 System.out.println(text);
  14.         }
  15.         public void setListener(IClickListener listener) {
  16.                 this.listeners.add(listener);
  17.         }
  18.         public void onClick() {
  19. //              for(IClickListener l : listeners) {
  20. //                      l.onClick("click");
  21. //              }
  22.                 listeners.forEach(System.out::println); // 동일 동작
  23.         }
  24. }
  25. class Dialog {
  26.         public void doOnClick(String text) {
  27.                 System.out.println(text);
  28.         }
  29. }
  30. @FunctionalInterface // 단일추상메소드 인터페이스임을 알림
  31. // 컴파일러가 메소드가 하나만 존재해야 한다는 것을 보장.
  32. interface IFoo { // 단일 인터페이스
  33.         void foo(String s, String s1);
  34. //      void goo(); // 두개는 선언 못한다.
  35.        
  36. }
  37.  
  38. @FunctionalInterface
  39. interface IGoo {
  40.         void goo();
  41. }
  42. public class Ex2 {
  43.         public static void goo(String s ) {
  44.                 System.out.println("goo" + s);
  45.         }
  46.         public static void main(String[] args) {
  47.                 IFoo foo = (s, s1) -> System.out.println(+ s1);
  48. //              IFoo foo = s -> System.out.println(s); // 인자가 하나인 경우 괄호가 생략 가능하다.
  49.                 foo.foo("d""c");
  50.                
  51.                 Button1 btn = new Button1();
  52.                 // 메소드 레퍼런스
  53.                 // 메소드를 맵핑 시킨다.
  54.                
  55.                 Dialog dialog = new Dialog();
  56.                 btn.setListener(dialog::doOnClick); // 타입만 맞춰주면 내부적으로 연결한다.
  57.                 btn.setListener(System.out::println);
  58.                
  59.                 btn.setListener(Ex2::goo);
  60.                
  61.                 btn.onClick();
  62.                
  63.                
  64.                 String[] labels = {"AAA","BBB","CCC"};
  65.                
  66.                 Stream<Button1> stream = Arrays.stream(labels).map(Button1::new); // Construct Reference
  67.                 stream.forEach(Button1::onClick);
  68.         }
  69. }


'java' 카테고리의 다른 글

Java 8 신기능 정리 - Stream  (0) 2014.07.02
Java 8 신기능 정리 - Default Method  (0) 2014.07.02
Java 8 신기능 정리 - Lambda Expression  (0) 2014.07.01
Java7 의 신기능 정리  (0) 2014.07.01
Java 7 try catch 문법. autocloseable  (0) 2014.06.20

Java 8 2014/03/18 Released

 언어의 형태가 바뀌었다.

 순수객체지향 지향 -> Functional Programming. 

 병렬 지원 - 라이브러리, 언어 차원에서 지원

 C# 4(2009)에서 지원, C++ 11(2011)에서 지원 (Visual studio 2010, gcc 4.6,4.8)


람다 표현식

 - 실행할 함수구문의 블럭을 보낸다.

 - 마지막 표현식이 리턴 값이 된다.

 - 중괄호 사용 시 리턴을 표기해줘야 한다.

 - 선언과 동시에 구현한다. 


  1. class Worker implements Runnable {
  2.  
  3.         @Override
  4.         public void run() {
  5.                 System.out.println("Hello Thread.");
  6.         }
  7.  
  8. }
  9.  
  10. class LengthComparator implements Comparator<String> {
  11.  
  12.         @Override
  13.         public int compare(String o1, String o2) {
  14.                 return Integer.compare(o1.length(), o2.length());
  15.         }
  16.  
  17. }
  18.  
  19. public class Ex1 {
  20.  
  21.         public static void main(String[] args) {
  22.                 // old 1
  23.                 new Thread(new Worker()).start();
  24.                 // old 2
  25.                 new Thread(new Runnable() { // assistance 가 지원된다.
  26.  
  27.                                         @Override
  28.                                         public void run() {
  29.                                                 // blah blah
  30.                                                 System.out.println("old_2");
  31.                                         }
  32.                                 }).run();
  33.  
  34.                 // new
  35.                 new Thread(() -> System.out.println("Hello") // 실행할 함수 구문의 블럭을 보낸다.
  36.                 // 인터페이스의 형태로 보낸다. functional interface
  37.                 ).start();
  38.                
  39.                 int oldCom = new LengthComparator().compare("f""s");
  40.                 Comparator<String> lengthComparator = (String first, String second) -> Integer
  41.                                 .compare(first.length(), second.length()); // 마지막 표현식이 리턴 값이 된다.
  42.                 Comparator<String> lenCom = (first, second) -> {
  43.                         return Integer.compare(first.length(), second.length()); //중괄호 사용시 리턴을 줘야한다.
  44.                 };
  45.                 System.out.println(oldCom);
  46.                 lengthComparator.compare("com""com");
  47.                 lenCom.compare("com""com2");
  48.                
  49.                 Button button = new Button();
  50.                 button.setButtonListener(()->System.out.println("click")); // 선언하며 구현한다.
  51.                 button.setButtonListener(new IButtonListener() {
  52.                        
  53.                         @Override
  54.                         public void onClick() {
  55.                                 System.out.println("old_click");
  56.                         }
  57.                 });
  58.                 // 옵저버 패턴의 구현 형식이 바뀌게 된다.
  59.                 button.click();
  60.         }
  61. }
  62. interface IButtonListener {
  63.         void onClick();
  64. }
  65. class Button {
  66.         IButtonListener listener;
  67.         void setButtonListener (IButtonListener listener) {
  68.                 this.listener = listener;
  69.         }
  70.         void click() {
  71.                 if(listener != null) {
  72.                         listener.onClick();
  73.                 }
  74.         }
  75. }
  76.  
  77. class Dialog implements IButtonListener {
  78.  
  79.         @Override
  80.         public void onClick() {
  81.                 System.out.println("click");
  82.         }
  83.        
  84. }


Java7의 달라진점은 크게 5가지로 정리할수 있다.


 1) Java String Switch

 2) 이진 표현과 _ 추가

 3) Multi-Exception Catch 향상된 예외처리

 4) Diamond Operator 

 5) Auto Closable 향상된 자원관리


  1. public class Ex1 {
  2.         public static void main(String... args) {
  3.                 // 1)
  4.                 int n = 10;
  5.                 switch (n) { // 이전 - int, enum 만 사용 가능
  6.                 case 1:
  7.                 case 2:
  8.                 }
  9.                 String s = "안녕";
  10.                 switch (s) { // java7 이후. String 도 사용 가능.
  11.                 case "안녕":
  12.                 case "hello":
  13.                 }
  14.  
  15.                 // 2)
  16.                 long old_l = 100000; // 실생활 1,000,000
  17.                 long new_l = 1_000_000; // 컴파일러에 의해 무시되지만 가독성이 증가
  18.                 int b_n = 0b1, b_2 = 0b10, b_3 = 0b1111_1010_1111; // 2진수 표현
  19.                
  20.                
  21.                 // 3)
  22.                 try {
  23.                         foo(n);
  24.                 } catch (ExceptionOne | ExceptionTwo | ExceptionThree e) { // 동일한 예외는 묶어서 관리한다.
  25.                         e.printStackTrace();
  26.                 }
  27.                
  28.                 // 4)
  29.                 List<Long> list = new ArrayList<>();
  30.                 list.add(old_l);
  31.                 list.add(new_l);
  32.                 list.add((long) b_n);
  33.                 list.add((long) b_2);
  34.                 list.add((long) b_3);
  35. //              list.addAll(Arrays.asList(old_l,new_l,b_n,b_2,b_3));
  36.                
  37.                 // 5)
  38.                 try(FileOutputStream fos = new FileOutputStream("test.txt"); // AutoClosable C# 에서 사용되는 기능
  39.                                 DataOutputStream dos = new DataOutputStream(fos)) {
  40.                         dos.writeUTF("xxx");
  41.                        
  42.                 } catch (IOException e) {
  43.                        
  44.                 } catch (Exception e) {
  45.                        
  46.                 }
  47.                
  48.                
  49.                
  50.  
  51.         }
  52.  
  53.         static void foo(int n) throws ExceptionOne, ExceptionTwo, ExceptionThree {
  54.                 if (== 0)
  55.                         throw new ExceptionOne();
  56.                 if (== 1)
  57.                         throw new ExceptionTwo();
  58.                 if (== 2)
  59.                         throw new ExceptionThree();
  60.  
  61.         }
  62. }
  63.  
  64. class ExceptionOne extends Exception {
  65.         private static final long serialVersionUID = -5677634028059042523L;
  66.  
  67. }
  68.  
  69. class ExceptionTwo extends Exception {
  70.         private static final long serialVersionUID = -6269740256108905025L;
  71.  
  72. }
  73.  
  74. class ExceptionThree extends Exception {
  75.         private static final long serialVersionUID = -8353059137079175265L;
  76. }


'java' 카테고리의 다른 글

Java 8 신기능 정리 - Method Reference, Construct Reference  (0) 2014.07.02
Java 8 신기능 정리 - Lambda Expression  (0) 2014.07.01
Java 7 try catch 문법. autocloseable  (0) 2014.06.20
코드 품질 관리  (0) 2014.04.17
Java Apn 샘플코드  (0) 2014.04.14

객체지향 5대 원칙

SOLID

SRP - 단일 책임의 법칙 : 클래스는 단 하나의 책임만을 가져야 한다.

OCP - 개방 폐쇄의 법칙 : 수정에는 닫혀있고 확장에는 열려있어야한다.

LSP - 리스코프의 치환법칙 : 자식은 부모로 대체 가능해야한다.

ISP - 인터페이스 분리의 법칙 : 범용 인터페이스 보다는 세분화된 인터페이스가 낫다.

DIP - 의존 관계역전의 법칙 : 구체 클래스에 의존하지 말고 인터페이스에 의존해라.


디자인 패턴


생성 (5)

Singleton : 하나의 클래스로 어디서든 접근 가능한 객체

Abstract Factory : 추상적인 부품을 통한 추상적 제품의 조립 (팩토리도 인터페이스 기반으로 만들자)

Factory Method : 변하지 않는 것은 부모가, 변하는것(객체생성이라) 자식이 오버라이딩

Builder : 동일한 공정에 다른 표현을 가진 객체 생성

Prototype : 복사본(clone) 을 통한 객체 생성

구조 (7)

Adapter : 인터페이스 변경을 통해 다른 클래스 처럼 보이기

Bridge : 확장 용이성을 위한 계층의 분리

Proxy : 기존 요소를 대신하기 위한 클래스(대리자)

Remote : 원격 객체를 대신

Virtual : 기존 객체의 생성 비용이 클 때

Protection : 기존 객체에 대한 접근 제어.

Facade : 하위 시스템 단순화하는 상위 시스템

Composite : 복합객체를 만들기 위한 패턴

Decorator : Composite와 같은데 기능의 확장

Flyweight : 동일한 속성을 가진 객체는 공유

행위 (11)

Iterator : 열거. 복합객체의 내부구조와 관계없이 동일한 구조로 열거 (Iterable, Iterator<T>)

Visitor : 복합객체 요소의 연산을 수행

Observer : 하나의 사건 발생 시 등록된 여러 객체에 전달

State : 상태에 따른 동작의 변화

Chain of Responsibility : 사건 발생 시 첫번째 객체가 처리 불가 시 다음으로 전달

Mediator : M:N 의 객체관계를 객체와 중재자 간의 1:1 관계로 단순화

Template Method : 변하지 않는것은 부모가, 변하는 것은 자식이 오버라이딩

Strategy : 알고리즘의 변화를 인터페이스기반의 클래스로 분리

Memento : 캡슐화를 위반하지 않고 객체의 상태를 저장 및 복구

Command : 명령의 캡슐화를 통한 Redo/Undo Macro

Interpreter : 간단한 언어를 설계하고 언어 해석기를 만들어 사용



Facade 패턴

 - 코드 랩핑(Code Wrapping)을 통해 의존성을 낮춘다.


  1. class Hotel {
  2.         // 호텔 정보
  3. }
  4.  
  5. class Flight {
  6.         @SuppressWarnings("unchecked")
  7.         public List<Flight> getFlightsFor(Date from, Date to) {
  8.                 return Collections.EMPTY_LIST;
  9.         }
  10. }
  11.  
  12. class HotelBooker {
  13.         @SuppressWarnings("unchecked")
  14.         public List<Hotel> getHotelNamesFor(Date from, Date to) {
  15.                 return Collections.EMPTY_LIST;
  16.         }
  17. }
  18.  
  19. class FlightBooker {
  20.         @SuppressWarnings("unchecked")
  21.         public List<Flight> getFlightNamesFor(Date from, Date to) {
  22.                 return Collections.EMPTY_LIST;
  23.         }
  24. }
  25.  
  26. class TravelFacade { // 코드 랩핑, 사용자는 Hotel, FLight에 대해 알 필요 없다.
  27.         private HotelBooker hotelBooker;
  28.         private FlightBooker flightBooker;
  29.  
  30.         public void getFlightAndHotels(Date from, Date to) {
  31.         }
  32.  
  33.         public HotelBooker getHotelBooker() {
  34.                 return hotelBooker;
  35.         }
  36.  
  37.         public FlightBooker getFlightBooker() {
  38.                 return flightBooker;
  39.         }
  40. }
  41.  
  42. public class Ex1 {
  43.  
  44.         public static void main(String[] args) {
  45.         }
  46.  
  47. }


+ Recent posts