문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top