This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
If there are two threads running and there are two methods, one is synchronized and the other is not..
first thread is accessing the non synchronized method (which is a lengthy one) of the object and it's on it's half way and suddenly the second thread comes to access the synchronized method of that object.. which means it's going to lock the object..
Now in this scenario what happens..... two threads are accessing two different methods but when the object is locked by the second thread, what will happen to the first thread and the method it was processing...
Any thread can execute any unsynchronized method at any time.
There's no such thing as "locking an object". The only thing the synchronized keyword does for mutual exclusion is to obtain a lock and (waiting first if some other thread already holds it) and prevent other threads from obtaining that lock. By using synchronization, you can only prevent other threads from executing code that syncs on the same lock. It's a cooperative paradigm.