I use TestNG to run tests in parallel and want to be careful about possible synchronization issues with helper classes and utilities. As far as I know, each test is its own object, transparently created by the tester. Thus, I do not need to worry about synchronizing anything non-static, since it would be an object created in the stream and therefore not visible to others.
However, when I call this external journal function, I wrote, do I need to synchronize it? Is there a possible race condition when thread-1 enters and sets threadName = "Thread-1", then thread-2 enters and sets SAME threadName variable = "Thread-2", and then thread-1 selects the backup and prints "- -foo | thread-2 "? Do I need to synchronize this method?
public static void log(String _message) { String threadName = Thread.currentThread().getName(); log.println("--" + _message + " | Thread: " + threadName); }
source share