How to identify an Application as Single threaded or Multi threaded?
How can i know whether the Application i am developing is single threaded or multi threaded? For example is StackOverflow a multi threaded or single thread Application?
We all login into stackoverflow, does that mean... at the same time n users are trying to access stackoverflow login class... checkLogin
Method?
So should we declare the checkLogin meth开发者_JAVA百科od synchronized
?
How can you possibly not know whether the application you are developing is multithreaded? You're the developer!
However in Java, unless you have completely managed to avoid using Thread.start(), Swing, AWT, RMI, garbage collection, a servlet container, etc etc etc, your application is multithreaded.
StackOverflow is not a common (desktop) application, it's a web application.
Web applications run on some sort of application server, which is almost always a multi-threaded program.
Regarding synchronized methods, you only need to add synchronization if multiple threads executing the method at the same time could cause unexpected behavior. That usually - but not always - happens when the method modifies shared variables (a counter variable, for instance) or accesses some limited resource (a socket for example).
You can check whether a common application is multithreaded by using a debuger like OllyDbg
精彩评论