The code below is the source code from jdk6, this is an implementation of writing to BufferedWriter , calling synchronized there in the body of the function, I think write() in BufferedWriter is thread safe. Btw, write(String) is implemented by calling write(String,int,int) .
public void write(String s, int off, int len) throws IOException { synchronized (lock) { ensureOpen(); int b = off, t = off + len; while (b < t) { int d = min(nChars - nextChar, t - b); s.getChars(b, b + d, cb, nextChar); b += d; nextChar += d; if (nextChar >= nChars) flushBuffer(); } } } }
source share