Synchronizing on the class would be cumbersome. Presumes that only 1 stream that uses this class would ever be in use. So, it'd affect threads outside of the one stream being run. Given the circumstances, the local variable lock is appropriate, but should probably be final to ensure it isn't accidentally re-created after this classes instance is created.