extends Thread or implements Runnablerun(){ while(true){ if (checkParameter){action(getParameters)} else{Thread.sleep(200);//the sleep duration is according to Ur program} } }boolean checkParameter(){//check the state changing here, eg, dom parse xml} String[] getParameters(){//fetch the parameters from here, eg, dom parse xml}you could use an Object to replace the persistence as well. eg, class someThing{ void setParameters(!@#%^); type getParameters(); void setState(state: boolean); boolean getState(); }if you use multi-thread, remember to add synchronized before checkParameter & getParameters.regards
but actually i am programming a Multi-Media Service Center Gateway. your code is good, but the problem is you set the thread sleep for a period, how you cope with if the message arrive the gateway while the thread just sleep?
u r doing realtime system,huh? eg,request is coming -> parse the request -> write the request string into xml(take xml for example). the thread is loop cheking the state, the sleep is just a rest forCPU controller, and the sleep time you could ignore, feel that? the sleep time is too short to even you could not take aware of .regards
static void sleep(long millis)milliseconds is the parameter of the sleep, so u get it, huh?
heh, well, now i am clear. that means i don't need to consider the sleep time piece. :D Cheers mate!!! best wishes
---------------------
可以做成单机版的socket,或其他带service性质的都可以。
用线程的方法怎么实现?
---------------------
循环检查 持久化物件中的参数。
while(true){
if (checkParameter){action(getParameters)}
else{Thread.sleep(200);//the sleep duration is according to Ur program}
}
}boolean checkParameter(){//check the state changing here, eg, dom parse xml}
String[] getParameters(){//fetch the parameters from here, eg, dom parse xml}you could use an Object to replace the persistence as well.
eg, class someThing{
void setParameters(!@#%^);
type getParameters();
void setState(state: boolean);
boolean getState();
}if you use multi-thread, remember to add synchronized before checkParameter & getParameters.regards
eg,request is coming -> parse the request -> write the request string into xml(take xml for example). the thread is loop cheking the state, the sleep is just a rest forCPU controller, and the sleep time you could ignore, feel that? the sleep time is too short to even you could not take aware of .regards
:D Cheers mate!!!
best wishes