Question

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.

Was it helpful?

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.

OTHER TIPS

No you dont need any synchronziation in this situation, synchronization is when multiple threads access shared data.

Synchronized methods are used when you don't want two threads to operate on any synchronized method at one time. If the application is single threaded there is no point taking a lock and adding an overhead of synchronization.

No, you should not as it will affect your performance. Synchronization should not be used if you are doing all in one thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top