how to lock a function while it is in processing?
i am using threads to write my game server side. anyone have any idea on how to lock a function while it is in process? then it wl continue after a process. appreciate very much
i am using threads to write my game server side. anyone have any idea on how to lock a function while it is in process? then it wl continue after a process. appreciate very much
thank for reply..but i want to lock the function untill the process is done then only start another process, not synchronize..
http://www.iut-info.univ-lille1.fr/docs/tutorial/uiswing/misc/threads.html
http://www.oreilly.com/catalog/expjava/excerpt/index.html
http://www.javaworld.com/jw-04-1996/jw-04-synch.html
public void run() {
try {
char charBuffer[] = new char[1];
// while we have an incoming stream
while(in.read(charBuffer,0,1) != -1) {
// create a string buffer to hold the incoming stream
StringBuffer stringBuffer = new StringBuffer(8192);
// while the stream hasn't ended
while(charBuffer[0] != '\0') {
// add the character to our buffer
stringBuffer.append(charBuffer[0]);
in.read(charBuffer, 0 ,1);
}
if(stringBuffer.toString().equals("IP")){
getMachineId(this.getIP());
} else{
// analysis the XML
parseReceivedXML(stringBuffer.toString());
}
}
} catch(IOException ioe) {
server.writeActivity("Client IP: " + ip + " caused a read error "
+ ioe + " : " + ioe.getMessage() + "and has been disconnected.");
} finally {
killClient();
}
}
above is my run() code. i want to lock the function parseReceivedXML() and release it to the waiting thread after a thread finish process. i want the threads queue up to run in this function. please help