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

[184 byte] By [gracecheaha] at [2007-11-27 10:54:10]
# 1

Google for the following phrase.

synchronized +java

macrules2a at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 2

thank for reply..but i want to lock the function untill the process is done then only start another process, not synchronize..

gracecheaha at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 3

Do a google search for:

Thread join +java

macrules2a at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 4

anyone please explain abit.. i am really no idea on it...

gracecheaha at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 5

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

macrules2a at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 6

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

gracecheaha at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 7

So make parseReceivedXML synchronized.

dwga at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...
# 8

cant work....the function is interupted if another process calling it... T.T

gracecheaha at 2007-7-29 11:48:40 > top of Java-index,Java Essentials,New To Java...