I have a method that access some DATABASE and write the result to a file. Like this...
yyy class will be INSTANTIATE by the
servlet.
The point is IF some request execute the first line (#1), it MUST execute the second line (#2) IMMEDIATELY because I want to preserve the order of line that is writing to file. If some other threading (by another client request) execute between #1 and #2 of firt request, I'll have a file output like this:
-- somefile.txt (just an example) --
BD - Autoincrement column = 2
BD - Autoincrement column = 1
I tried to put synchronized keyword in the method, but it didn't work.
My
test: I press the F5 key (refresh) of browser many times (quickly)... and when I see the file, some line is not in order.
Why didn't synchronized help me?