달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'분류 전체보기'에 해당되는 글 87

  1. 2008.03.13 MySQL Master/Slave Connection
  2. 2008.03.12 Spring 2.5 설정 2
  3. 2008.03.11 Spring 2.5 Test
  4. 2008.03.10 쓰레드 동기화 2
  5. 2007.05.20 ecto를 이용한 tistory 원격 블로깅
  6. 2007.04.13 탭을 이용한 콘트롤 이동 1
  7. 2007.04.13 맥에서 패키지 관리하기
  8. 2007.02.07 맥 팁~~~ 2
  9. 2007.01.28 Mac에서 윈도우즈 사용
  10. 2007.01.28 Mac 설정 관련
2008. 3. 13. 13:24

MySQL Master/Slave Connection DB2008. 3. 13. 13:24

Using Master/Slave Replication with ReplicationConnection

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-replication-connection.html

springframework의 declarative txn. mgt.에서 readOnly=true를 주면 setReadOnly 메소드를 사용하지 않을까 ???

2008/03/13 이렇게 시도해 보니 진짜 생각한 대로 동작했다. 그런데 테스트할 때 문제가 있었다. AbstractTransactionalXXXTest를 상속 받은 경우에는 항상 rollback 되기 때문에 transaction aspect이 동작하지 않는 것 같다. 그래서 readOnly transactional method에서 CUD를 해도 exception이 발생하지 않았다. 그래서 AbstractJUnit4SpringContextTests를 사용했다.

이제 해 볼 것은 readOnly 메소드에서 transactional method를 호출할 때 제대로 master/slave로 호출이 분배되는지 확인하는 것이다.

이건 안된다.

readOnly 메소드가 transactional 메소드를 호출하면 read only connection에서 데이터를 변경하려고 시도했다고 exception을 발생시킨다.

Load Balancing JDBC Pool (lbpool)

http://code.tailrank.com/lbpool

예제)
1. replication.properties

replication.driverClassName=com.mysql.jdbc.ReplicationDriver
replication.url=jdbc:mysql://master-ip,slave-ip-1, slave-ip-2/dbname?autoReconnect=true
jdbc.username=xxx
jdbc.password=yyy

2. applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<context:property-placeholder
location="classpath:replication.properties" />

<tx:annotation-driven transaction-manager="transactionManager" />

<context:component-scan base-package="net" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${replication.driverClassName}"
p:url="${replication.url}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />

<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
p:configLocation="classpath:sqlMap-config.xml"
p:dataSource-ref="dataSource" />

<bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClientTemplate"
p:sqlMapClient-ref="sqlMapClient" />

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />

<bean id="someDao"
class="net.SomeDaoImpl"
p:sqlMapClientTemplate-ref="sqlMapClientTemplate" />
</beans>

3. ManageArticleServiceImpl

@Service
@Transactional(readOnly=true)
public class ManageArticleServiceImpl implements ManageArticleService {
@Autowired
private SomeDao SomeDao;

@Autowired
private CountService countService;

@Transactional(readOnly=false, propagation = Propagation.REQUIRED)
public Article getArticle(Long articleId) {
Article article = someDao.find(articleId);

countService.read(article);

return article;
}
}

4. CountServiceImpl

@Service
@Transactional(readOnly=true)
public class CountServiceImpl implements CountService {
@Autowired
private SomeDao someDao;

@Transactional(readOnly=false, propagation = Propagation.REQUIRED)
public void read(Article article) {
article.read();
someDao.update(article);
}
}

:
Posted by codetemplate
2008. 3. 12. 11:40

Spring 2.5 설정 프레임워크2008. 3. 12. 11:40

1. 기본 설정 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <!-- this switches on the load-time weaving <context:load-time-weaver /> --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- <context:annotation-config /> <tx:annotation-driven /> --> <context:component-scan base-package="foo" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" />

:
Posted by codetemplate
2008. 3. 11. 20:36

Spring 2.5 Test 프레임워크2008. 3. 11. 20:36

.Superclass

AbstractJUnit4SpringContextTests AbstractTransactionalJUnit4SpringContextTests

AbstractTransactionalTestNGSpringContextTests

. Util.

ReflectionTestUtils ModelAndViewAssert

- 이 클래스에서 상속을 받아서 테스트 작성

. Annotation Tags

@ContextConfiguration(locations = { "classpath:applicationContext.xml"" })

base 클래스에 정의되고 child 클래스에 정의되면 override가 아니라 append됨

@Autowired @Resource @IfProfileValue

- 특정 환경 변수가 설정되었을 때만 수행 - 예). @IfProfileValue(name="java.vendor", value="Sun Microsystems Inc.") public void testXXX() {

...

}

@ProfileValueSourceConfiguration @DirtiesContext @ExpectedException

예). @ExpectedException(SomeBusinessException.class) public void testXXX()

@Timed

예). @Timed(millis=1000) public void testXXX()

@Repeat @Rollback

예). @Rollback(false) public void testXXX()

@NotTransactional

:
Posted by codetemplate
2008. 3. 10. 17:32

쓰레드 동기화 Java2008. 3. 10. 17:32

CyclicBarrier를 이용하는 방법.
public class SynchronizedThread extends Thread {
private CyclicBarrier entryBarrier; private CyclicBarrier exitBarrier;
public SynchronizedThread(Runnable runnable, CyclicBarrier entryBarrier, CyclicBarrier exitBarrier) {
super(runnable); this.entryBarrier = entryBarrier; this.exitBarrier = exitBarrier;
}
@Override public void run() {
try {
entryBarrier.await(); super.run(); exitBarrier.await();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
public class SynchronizedThreadTest {
@Test public void testMultithread() throws InterruptedException, BrokenBarrierException {
Runnable r = new Runnable() {
public void run() {
System.out.println("thread=" + Thread.currentThread().getId() + ", started !!!"); long millis = 3 * 1000l; try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
} System.out.println("thread=" + Thread.currentThread().getId() + ", done !!!");
}
};
int numberOfThreads = 10;
System.out.println("before start");
CyclicBarrier entryBarrier = new CyclicBarrier(numberOfThreads + 1); CyclicBarrier exitBarrier = new CyclicBarrier(numberOfThreads + 1);
for (int i = 0; i < numberOfThreads; i++) {
// new Thread(r).start(); new SynchronizedThread(r, entryBarrier, exitBarrier).start();
}
System.out.println("after start");
System.out.println("before entryBarrier.await();"); entryBarrier.await();
System.out.println("before exitBarrier.await();"); exitBarrier.await();
System.out.println("after exitBarrier.await();");
}
}
:
Posted by codetemplate
2007. 5. 20. 16:14

ecto를 이용한 tistory 원격 블로깅 Mac2007. 5. 20. 16:14

ecto는 http://ecto.kung-foo.tv에서 다운받을 수 있다.
설정하는 방법은 http://manual.tistory.com/719를 참조하면 된다.


ecto.jpg

:
Posted by codetemplate
2007. 4. 13. 17:22

탭을 이용한 콘트롤 이동 Mac2007. 4. 13. 17:22

맥에서 대화상자의 컨트롤은 기본 설정에서는 키보드로 이동/선택이 안된다.
이를 사용하려면 아래와 같이 설정 변경을 해 주어야 한다.

시스템 환경 설정... / 키보드 & 마우스 / 키보드 단축키

메뉴에서 하단의 "모든 컨트롤" 선택

컨트롤 간의 이동은 탭
컨트롤 선택은 스페이스
:
Posted by codetemplate
2007. 4. 13. 16:32

맥에서 패키지 관리하기 Mac2007. 4. 13. 16:32

Fink라는 오픈소스를 설치하면
sudo dselect
를 실행하여 패키지 관리를 할 수 있다.

http://cafe.naver.com/ArticleRead.nhn?clubid=12175294&menuid=&boardtype=L&page=11&articleid=20920
:
Posted by codetemplate
2007. 2. 7. 16:34

맥 팁~~~ Mac2007. 2. 7. 16:34

TextMate에서 한글 사용하기

http://jiyoon.unfix.net/2007/3/30/textmate-hangul-fonts

웹페이지를 메일로 보내기

cmd+I

VLC 자막 설정법

http://digikor.com/49

iTunes 한글 깨짐 처리

해결책

:
Posted by codetemplate
2007. 1. 28. 18:07

Mac에서 윈도우즈 사용 Mac2007. 1. 28. 18:07

부팅 OS 선택하기
- 부팅시 옵션키 누르면 선택할 수 있음

부팅 순서 변경하기
- 환경설정 / startup disk로

부트캠프 없이 윈도우즈만 사용하기
http://cafe.naver.com/ArticleRead.nhn?clubid=12175294&menuid=&searchtype=1&query=%C0%A9%B5%B5%BF%EC%C1%EE%B8%B8&page=3&articleid=8775


지금은 패러랠즈를 이용해서 윈도우즈를 사용하고 있는데 얼마 후에 맥북 프로가 생기면 이 화이트맥은 아마 집에서 윈도우즈로만 사용할 것 같다는...
:
Posted by codetemplate
2007. 1. 28. 18:02

Mac 설정 관련 Mac2007. 1. 28. 18:02

마우스 속도 조정하기
defaults write -globalDomain com.apple.mouse.scaling -float 3.0
default는 1.7...
:
Posted by codetemplate