소스좀 봐주세요 ㅠ쓰레드 관련 질문입니다 ㅠ

String diaryID=;
int status=0;
if(e.getSource()== accept){
HttpClient client = new HttpClient();
//Login
PostMethod post = new PostMethod(http://edda.in/userloginprocess.jsp);
String tempid=,temppw=;
try{
tempid = new String(ID.getText().getBytes(EUC-KR),8859_1);
temppw = new String(password.getText().getBytes(EUC-KR),8859_1);
}catch(Exception err){
err.printStackTrace();
}
tempid = tempid.trim();
temppw = temppw.trim();
NameValuePair[] data = new NameValuePair[]{
new NameValuePair(nick, tempid),
new NameValuePair(password, temppw)
};
post.setRequestBody(data);
try{
status = client.executeMethod(post);

}catch(Exception err){

}

String redirectLocation=;

Header locationHeader = post.getResponseHeader(location);
if(locationHeader!=null){
redirectLocation=locationHeader.getValue();
for(int i=34;iredirectLocation.length();i++){
diaryID+=String.valueOf(redirectLocation.charAt(i));
}
}else
JOptionPane.showMessageDialog( null, Login Error!!, Error, JOptionPane.ERROR_MESSAGE);

//End Login
today.setTime(new Date());
//Write

try {
if(status!=200 && locationHeader!=null){
String tempsub=,tempcontents=;
try{
tempsub = new String(subject.getText().getBytes(EUC-KR),8859_1);
tempcontents = new String(contents.getText().getBytes(EUC-KR),8859_1);
}catch(Exception err){
err.printStackTrace();
}
NameValuePair[] wrdata = new NameValuePair[]{
new NameValuePair(diary,diaryID),
new NameValuePair(year,String.valueOf(today.get(Calendar.YEAR))),
new NameValuePair(month,String.valueOf(today.get(Calendar.MONTH)+1)),
new NameValuePair(date,String.valueOf(today.get(Calendar.DATE))),
new NameValuePair(background,),
new NameValuePair(category,0),
new NameValuePair(title,tempsub),
new NameValuePair(body,tempcontents),
new NameValuePair(permission,String.valueOf(permission.getSelectedIndex())),
new NameValuePair(copy,off),
new NameValuePair(interior,random.gif)
};
String Write_url=http://edda.in/writediaryprocess.jsp;
PostMethod wmethod = new PostMethod(Write_url);wmethod.setRequestBody(wrdata);
client.executeMethod(wmethod);
JOptionPane.showMessageDialog( null, Complete, Complete, JOptionPane.INFORMATION_MESSAGE);}
else{
JOptionPane.showMessageDialog( null, Cannot connect!!, Error, JOptionPane.ERROR_MESSAGE);
}
}catch (Exception err){
err.printStackTrace();
}
}
accept버튼을 누르면 저 위에 있는 사이트에 로그인을 하고 글을 쓰는 기능을 구현한 것입니다.

액션리스너 부분을 긁어봤네요 ^^

accept버튼을 여러번 누르면 글이 여러번 올라가게됩니다.

근데-_-macro.java라는 파일을 제가 따로 만들어서 매크로를 실행시키면 1분마다 시간체크를 하고 제가 원하는 시간이 되면 글이 올라가게 하게 구현했습니다.
public void run() {
int i=0;
while(true){
System.out.println(Macro Waiting. + i);
i++;try{
Thread.sleep(60000);//60000으로 지정해줘서 1분에 한번씩 체크.
}catch(Exception e){

}
today.setTime(new Date());

if(today.get(Calendar.HOUR_OF_DAY)==0 && today.get(Calendar.MINUTE)==5){
&nbspsp;HttpClient client = new HttpClient();
//Login
PostMethod post = new PostMethod(http://edda.in/userloginprocess.jsp);
String tempid=,temppw=;
try{
tempid = new String(id.getBytes(EUC-KR),8859_1);
temppw = new String(pass.getBytes(EUC-KR),8859_1);
}catch(Exception err){
err.printStackTrace();
}
tempid = tempid.trim();
temppw = temppw.trim();
NameValuePair[] data = new NameValuePair[]{
new NameValuePair(nick, tempid),
new NameValuePair(password, temppw)
};
post.setRequestBody(data);
try{
status = client.executeMethod(post);

}catch(Exception err){

}
String redirectLocation=;
Header locationHeader = post.getResponseHeader(location);

if(locationHeader!=null){
redirectLocation=locationHeader.getValue();
for(int j=34;jredirectLocation.length();j++){
did+=String.valueOf(redirectLocation.charAt(j));
}

//End Login
today.setTime(new Date());
//Write

try {
if(status!=200 && locationHeader!=null){
String tempsub=매크로 글남기기tempcontents=이건 매크로;;;
try{
tempsub = new String(tempsub.getBytes(EUC-KR),8859_1);
tempcontents = new String(tempcontents.getBytes(EUC-KR),8859_1);
}catch(Exception err){
err.printStackTrace();
}
NameValuePair[] wrdata = new NameValuePair[]{
new NameValuePair(diary,did),
new NameValuePair(year,String.valueOf(today.get(Calendar.YEAR))),
new NameValuePair(month,String.valueOf(today.get(Calendar.MONTH)+1)),
new NameValuePair(date,String.valueOf(today.get(Calendar.DATE))),
new NameValuePair(background,),
new NameValuePair(category,0),
new NameValuePair(title,tempsub),
new NameValuePair(body,tempcontents),
new NameValuePair(permission,3),
new NameValuePair(copy,off),
new NameValuePair(interior,random.gif)
};
String Write_url=http://edda.in/writediaryprocess.jsp;
PostMethod wmethod = new PostMethod(Write_url);wmethod.setRequestBody(wrdata);
client.executeMethod(wmethod);
System.out.println(Complete);

}
else{
JOptionPane.showMessageDialog( null, Cannot connect!!, Error, JOptionPane.ERROR_MESSAGE);
}
}catch (Exception err){
err.printStackTrace();
}

//End write
}
}
}

}
run부분을 긁어봤습니다.

켜두면 밤 12시 5분에 글을 쓰게 되어있습니다 일단은;

근데 macro의 run부분이 글을 올리는 부분이기에 accept부분을 긁어서 거의 고치지 않고 붙였는데;

이상하게 쓰레드가 여러번 돌아가면 글이 여러번 써져야 하는데 그러지 않네요;;
음 정리 하자면

accept버튼을 여러번 누르면 글이 여러개 올라갑니다.

그러나 쓰레드가 여러번 돌아가면 그 돌아간 횟수만큼 글이 올라가야 하는데 맨 첫번째 시도에서만 글이 올라가고-_-

그 이후의 시도에서는 complete라고 뜨긴 하는데 글은 올라가지 않네요;;

분명히 run안의 부분은 accept를 눌렀을때 글을 쓰는 부분과 같고 accept버튼을 여러분 누르는것과 쓰레드의 while문이 계속 돌아가는것과 돌아가는 방법은 같을텐데 왜 쓰레드는 맨 처음 한번밖에 글이 써지지 않을까요?

어딜 찾아봐도 명쾌한 해답이 없네요..ㅠ

댓글 2

  • 비마중 2026.05.02

    아이코 실수; 기본이 복사 안되게..라-_-클릭한다는거 ㄹ깜빡했네요;

  • 먹딸기 2026.05.02

    블럭이 어디부터 인지 알아보기도 힘드네요.
    최소한 복사 해서 돌려볼수 있게는 해야 하는거 아닌가요?
    이거 보면서 타이핑해서 테스트 하기엔 너무 힘들어서 패스할께요.

프로그램 개발일반 다른 글

목록