안녕하십니까,
도움을 얻고자 이렇게 질문 드립니다.
두 개의 Timer 쓰레드를 돌려서 주기적으로
상대 단말에 메시지를 보내게 됩니다.
두 개의 쓰레드를 구동하기 때문에 동기화(Synchronized) 처리가 필요한 것 같은데
아래의 코드에 어떻게 추가해야 할지 잘 모르겠습니다.
시간이 없어서 이렇게 질문 올립니다. (시행착오가 많이 생길것 같아서...-.-;;;;;)
아래의 소스에서 동기화를 위한 코드를 어떻게 추가 해야 하나요?
Timer hellotimer = new Timer();
HelloMsgTimer helloMsgTimer = new HelloMsgTimer();
hellotimer.schedule(helloMsgTimer, 3000, 5000);
Timer alivetimer = new Timer();
AliveMsgTimer aliveMsgTimer = new AliveMsgTimer();
alivetimer.schedule(aliveMsgTimer, 2000, 2000);
class HelloMsgTimer extends TimerTask {
public void run() {
//특정 모뎀으로 hello 메시지 보내는 코드
TWRApp appContext = (TWRApp) getApplicationContext();
helloMsgtemp = appContext.mSharePicocastDevice.getPicocastHelloMessage();
helloMsgtemp.setPicocastHelloMessageTime((long) myLocation.getTime());
helloMsgtemp.setPicocastHelloMessageLatitude((double) myLocation.getLatitude());
helloMsgtemp.setPicocastHelloMessageLongitude((double) myLocation.getLongitude());
appContext.mSharePicocastDevice.sendPicocastHelloMessage(helloMsgtemp);
}
@Override
public boolean cancel() {
return super.cancel();
}
}
class AliveMsgTimer extends TimerTask { //hotpjs, 1217, added it for pico's alive message
@Override
public void run() {
Log.d(TAG, "AliveMsgTimer");
//특정 모뎀으로 Alive 메시지 보내는 코드
TWRApp appContext = (TWRApp) getApplicationContext();
aliveMsgtemp = appContext.mSharePicocastDevice.getPicocastAliveMessage();
aliveMsgtemp.setPicocastAliveMessageSender(picoSender);
aliveMsgtemp.setPicocastAliveMessageTime((long) System.currentTimeMillis());
appContext.mSharePicocastDevice.sendPicocastAliveMessage(aliveMsgtemp);
}
@Override
public boolean cancel() {
return super.cancel();
}
}
서현수현 아빠 배상.




동기화 타겟이 되어야 하는 공유자원이 무엇인지 알수가 없군요
서로 다른 메시지를 처리하는 것으로 보이는데...
동기화를 시키고 싶은 대상 부터 명확히 해야 할 것 같아요