2012년 2월 20일 월요일

Preventing database connection pool leaks

Preventing database connection pool leaks

http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html


A database connection pool creates and manages a pool of connections to a database. Recycling and reusing already existing connections to a database is more efficient than opening a new connection.
There is one problem with connection pooling. A web application has to explicitly close ResultSet's, Statement's, and Connection's. Failure of a web application to close these resources can result in them never being available again for reuse, a database connection pool "leak". This can eventually result in your web application database connections failing if there are no more available connections.
There is a solution to this problem. The Apache Commons DBCP can be configured to track and recover these abandoned database connections. Not only can it recover them, but also generate a stack trace for the code which opened these resources and never closed them.
To configure a DBCP DataSource so that abandoned database connections are removed and recycled add the following attribute to the Resource configuration for your DBCP DataSource:
removeAbandoned="true"
When available database connections run low DBCP will recover and recycle any abandoned database connections it finds. The default is false.
Use the removeAbandonedTimeout attribute to set the number of seconds a database connection has been idle before it is considered abandoned.
removeAbandonedTimeout="60"
The default timeout for removing abandoned connections is 300 seconds.
The logAbandoned attribute can be set to true if you want DBCP to log a stack trace of the code which abandoned the database connection resources.
logAbandoned="true"
The default is false.



POJO class sample.
-------------------------------------------
BasicDataSource bds = new BasicDataSource();
..
DB설정 부분..
..
..
아래 내용 추가.

bds.setRemoveAbandoned( true );
bds.setRemoveAbandonedTimeout( 60 );
bds.setLogAbandoned( true ); 

2012년 2월 14일 화요일

JAVA CLOSE_WAIT 관련 내용


JAVA CLOSE_WAIT 이슈는 자바의 버그에서 비롯된 것으로 판단됨.

관련 버그 내용.

bug: 6215050 java classes_nio (so) SocketChannel created in CLOSE_WAIT and never cleaned up.. File Descriptor leak
http://www.oracle.com/technetwork/java/javase/releasenotes-142123.html

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6215050


이와 관련한 내용 및 문제제기 관련 사이트 (해결방법은 아니므로 참고만 하세요.)
http://stackoverflow.com/questions/8326058/how-to-kill-tcp-connection-with-close-wait-state

https://forums.oracle.com/forums/thread.jspa?threadID=1160014

http://tux.hk/index.php?m=05&y=09&entry=entry090521-111844


http://www.thatisjava.com/java-core-apis/35975/

Push Notification 관련 정보 모음(작업중)


MQTT 를 이용한 tokudu
http://tokudu.com/2010/how-to-implement-push-notifications-for-android/


Push 서버 샘플
http://translate.googleusercontent.com/translate_c?hl=ko&langpair=en%7Cko&rurl=translate.google.co.kr&twu=1&u=http://tokudu.com/2010/how-to-implement-push-notifications-for-android/&usg=ALkJrhhmByybxQBUAMl9KHmjgPI7C1CXEw


클라이언트 연결유지 샘플
http://translate.googleusercontent.com/translate_c?hl=ko&langpair=en%7Cko&rurl=translate.google.co.kr&twu=1&u=http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html&usg=ALkJrhgRnSh33X2R5mo63HjSkzIBl4yhAA



[팁] Notification 을 이용한 실행시 Activity 중복 실행 막기
http://www.androidpub.com/index.php?mid=android_dev_info&category=127161&page=2&document_srl=796480

chkrootkit 사용

설치는 yum 또는 wget 을 이용하면 간편..

[root@test]#yum install chkrootkit

yum이 없을때는 wget 으로 다운로드.. 또는 사이트에서 직접 받아야겠지요.


[root@test root]#wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz

[root@test root]# tar zxvf chkrootkit.tar.gz

[root@test root]# cd chkrootkit-0.49

[root@test chkrootkit-0.49]# make sense


이후 실행하면 된다.

Oracle *.trc 파일정리


Oracle trc 파일정리: 7일이상 지난 파일들을 찾아서 삭제

find /opt/oracle/admin/TEST/bdump \( -ctime +7 -name '*.trc' \) -exec rm -f {} \;
find /opt/oracle/admin/TEST/udump \( -ctime +7 -name '*.trc' \) -exec rm -f {} \;


위 내용을 스크립트로 만들어서 crontab 에 등록해서 쓰면 좋겠지.

00 02 * * * oracle_log_del.sh

매일 새벽2시에 정리..