Search code examples
javamultithreadingmethodssynchronize

Do any methods have to be synchronized if there's only the main thread?


Do I really need to synchronize any methods if I'm not creating any threads (exception is the main). If so, can someone give a reason why and provide some examples please.


Solution

  • If you don't create any threads of your own, then no, you should not need to use the synchronized keyword. That's assuming you're not writing J2EE servlets or filters, or a library that others (who are using multiple threads) can call.