1. 스태틱으로 선언하여 클래스 메서드로 만듦
<bean id="객체ID" class="팩토리클래스" factory-method="생성메서드명">


2. 인스턴스 메서드로 만듦
<beam id="팩토리ID" class="팩토리클래스">
(--> static 메서드가 아니라 객체 먼저 생성 필요)

<bean id="객체ID" factory-bean="팩토리ID" factory-method="생성메서드명">


3. AbstractFactoryBean 상속 받아서 클래스 생성
- 단점 : Spring에서만 사용가능
- 장점 : 팩토리 메서드 지정 불필요. 직접 만들어보면 내부 동작 이해에 도움이 됨.

public class TestFactoryBean extends AbstractFactoryBean<Test> {

    @Override
    public Class<?> getObjectType() {
        ...
    }

    @Override
    protected Tire createInstance() throws Exception {
        ...
    }
...
}

<bean id="객체ID" class="팩토리빈클래스">



http://hangaebal.blogspot.kr/2014/06/spring-factory-method-factory-bean.html

-----------------------------------------------

*JavaScript
var a = 3;
var b = 2;
var max;

max = a > b ?  a : b;              - 가능
a > b ? max = a : max = b;     - 가능
-----------------------------------------------
*Java
int a = 1;
int b = 2;
int max;

max = a > b ?  a : b;              - 가능
a > b ? max = a : max = b;     - 문법 오류 (x)

-----------------------------------------------







http://hangaebal.blogspot.kr/2014/06/java-javascript-difference-between-java.html

*Map과 Properties의 차이
- Map : key나 value로 문자열 및 다른 타입의 객체도 사용 가능
- Properties : Map의 일종이지만, key나 value로 문자열을 다룰 때 주로 사용


*java.util.Properties 타입 :
<props>
 <prop key="키1">값1</prop>
 <prop key="키2">값2</prop>
 ...
</props>


*java.util.Map 타입 :
<map>
 <entry>
  <key>
   <value>키1</value>
  </key>
  <value>값1</value>
 </entry>
 <entry key="키2">
  <ref bean="값2의id"/>
 </entry>
 <entry key="키3" value="값3" />
 <entry key="키4" value-ref="값4의id" />
</map>



http://hangaebal.blogspot.kr/2014/06/spring-map-properties.html

Set provides uniqueness guarantee i.e.g you can not store duplicate elements on it, but it's not ordered.
List is an ordered Collection and also allowes duplicates.
Map is based on hashing and stores key and value in an Object called entry. It provides O(1) performance to get object, if you know keys, if there is no collision.

Another key difference between Set, List and Map are that Map doesn't implement Collection interface, while other two does.

Popular impelmentation of Set is HashSet, of List is ArrayList and LinkedList, and of Map are HashMap, Hashtable and ConcurrentHashMap.


-------------------------------------------------------------------
- Set : 중복이 불가해서 고유성은 보장되지만, 순서 유지 불가능
- List : 순서가 유지되고, 중복 가능
- Map : key와 value로 entry라 불리는 Object를 저장하고 찾는다. 키를 알고 있고, 충돌이 없다면, object를 얻는데 performance가 가장 좋다


- Set, List는 Collection 인터페이스를 구현했지만, Map은 아니다.

- 구현체 중 많이 쓰이는것
> Set : HashSet
> List : ArrayList, LinkedList
> Map : HashMap, Hashtable, ConcurrentHashMap.



출처 :
http://javarevisited.blogspot.kr/2011/11/collection-interview-questions-answers.html

http://hangaebal.blogspot.kr/2014/06/difference-between-set-list-and-map-in.html


 Node.js - Error connection lost the server closed the connection
Error: Connection lost: The server closed the connection.


var db_config = {
  host: 'localhost',
    user: 'root',
    password: '',
    database: 'example'
};

var connection;

function handleDisconnect() {
  connection = mysql.createConnection(db_config); // Recreate the connection, since
                                                  // the old one cannot be reused.

  connection.connect(function(err) {              // The server is either down
    if(err) {                                     // or restarting (takes a while sometimes).
      console.log('error when connecting to db:', err);
      setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
    }                                     // to avoid a hot loop, and to allow our node script to
  });                                     // process asynchronous requests in the meantime.
                                          // If you're also serving http, display a 503 error.
  connection.on('error', function(err) {
    console.log('db error', err);
    if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
      handleDisconnect();                         // lost due to either server restart, or a
    } else {                                      // connnection idle timeout (the wait_timeout
      throw err;                                  // server variable configures this)
    }
  });
}

handleDisconnect();



출처 :
http://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection

http://hangaebal.blogspot.kr/2014/06/nodejs-error-connection-lost-server.html

+ Recent posts