once a thread enters any sychorinsed method on an instance , no other thread can enter any other synchronised method on the same instance ? what does this line mean ?

also, how can one method be called by many threads at the same time on the same object ? (this is case when i not use sychronised) how is it possible?

Change the code in your previous post/question to make B b static. Now you have 2 threads each calling the sum method on the same object (static b).
If sum is synchronised then the second thread will be held up and won't be able to start executing sum until the first thread has finished executing it.

Change the code in your previous post/question to make B b static. Now you have 2 threads each calling the sum method on the same object (static b).
If sum is synchronised then the second thread will be held up and won't be able to start executing sum until the first thread has finished executing it.

u want to say is that even if that thread goes to sleep for a while, then even other thread can't enter it ? is this right ?

Yes. The second thread cannot enter the method until the first one leaves it, no matter how long that may take.

Yes. The second thread cannot enter the method until the first one leaves it, no matter how long that may take.

oh ya ya i get it. please explain my second line also. u have told only first part of my question.

I thought I did. "Change the code in your previous post/question to make B b static. Now you have 2 threads each calling the sum method on the same object (static b)." That's an example of one method being called by many threads at the same time on the same object

I thought I did. "Change the code in your previous post/question to make B b static. Now you have 2 threads each calling the sum method on the same object (static b)." That's an example of one method being called by many threads at the same time on the same object

okay! i really got it. thanks again! solved.

One exception to the holding of a lock when in a synchronized block is if the code calls the wait() method. It then releases the lock.

One exception to the holding of a lock when in a synchronized block is if the code calls the wait() method. It then releases the lock.

this answer is for what question ??

Yes, thanks for the correction Norm.

even if that thread goes to sleep for a while, then even other thread can't enter it

It was for the above question. If a thread calls wait() while in a synchronized block then another thread can enter the block.

Yes, thanks for the correction Norm.

.

One exception to the holding of a lock when in a synchronized block is if the code calls the wait() method. It then releases the lock.

.

It was for the above question. If a thread calls wait() while in a synchronized block then another thread can enter the block.

ohh! if notify being called when second thread is there in sychronized method, then what happened? means if that initial thread invokes which has called the wait() while second thread is inside the method?then ?

Write a test program and see what happens.

Read the API doc for the Object class

Write a test program and see what happens.

Read the API doc for the Object class

from where ?? how is it related to object API ?? tell further please

If you have questions about the API doc that you read in the Object class, copy and paste it here with your questions.

If you have questions about the API doc that you read in the Object class, copy and paste it here with your questions.

hey! i don't have questions about that. my question was simple. u said that read object API. y to read that ? give my question above 3-4 comments

You can not have read the API doc yet.
Read the API doc and then ask your questions.

Hi gourav
Norm is pointing you to the API doc for the Object class because that's where the wait and notify methods are defined and documented in complete detail.

It's very convenient for you if someone else extract the relevant info for you and presents it in terms of your question, but that's a lot of someone's time. You will find the answers to your questions in the API doc, but if you still have problems afterwards you can always come back here for clarification.
It's not easy reading the API doc at first, but you'll soon get the hang of it, and it's an absolutely essential skill for Java programmers at every level.

Hi gourav
Norm is pointing you to the API doc for the Object class because that's where the wait and notify methods are defined and documented in complete detail.

It's very convenient for you if someone else extract the relevant info for you and presents it in terms of your question, but that's a lot of someone's time. You will find the answers to your questions in the API doc, but if you still have problems afterwards you can always come back here for clarification.
It's not easy reading the API doc at first, but you'll soon get the hang of it, and it's an absolutely essential skill for Java programmers at every level.

sir, this answer is nice! but will u please tell me where can i get API so that i can read it and get info from it ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.