Question about nofityAll()

L

Love Rhino

I got some code that does the following:

methodA()
{

if ( something)
methodB(); //notifyAll() is called at the end of methodB().

notifyAll();

return value;
}


I'm wondering if this will cause any problems? Doing a google search
doesn't appear to be any problems.... hmmm...

thanks.
 
M

Matt Humphrey

Love Rhino said:
I got some code that does the following:

methodA()
{

if ( something)
methodB(); //notifyAll() is called at the end of methodB().

notifyAll();

return value;
}


I'm wondering if this will cause any problems? Doing a google search
doesn't appear to be any problems.... hmmm...

As long as we have no idea what your program is supposed to do there is no
way to tell if notifyAll has any meaning there. I feel pretty sure you have
no idea what it does either.

If you expect any help you're going to have to tell us what you are trying
to accomplish.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
F

Filip Larsen

Love Rhino wrote
I got some code that does the following:

methodA()
{

if ( something)
methodB(); //notifyAll() is called at the end of methodB().

notifyAll();

return value;
}


I'm wondering if this will cause any problems? Doing a google search
doesn't appear to be any problems.... hmmm...

If we assume that both methodA and methodB are marked as synchronized,
or more precisely, that the two calls to notifyAll() occur within the
same toplevel synchronized block, then the two calls should give same
result as just one call and should not give any problems regarding
thread scheduling logic.

However, it will probably be prudent to refactor the code such that a
notifyAll occur only once during invokation of methodA.


Regards,
 
A

Ann

Filip Larsen said:
Love Rhino wrote


If we assume that both methodA and methodB are marked as synchronized,
or more precisely, that the two calls to notifyAll() occur within the
same toplevel synchronized block, then the two calls should give same
result as just one call and should not give any problems regarding
thread scheduling logic.

However, it will probably be prudent to refactor the code such that a
notifyAll occur only once during invokation of methodA.


Regards,

I don't have direct experience, but from what I read it is better
to do too many notifyAll's than too few. Every "wait" should check
to make sure that the resource it is waiting for is indeed available
to it before proceeding.
 
J

John C. Bollinger

Ann said:
I don't have direct experience, but from what I read it is better
to do too many notifyAll's than too few. Every "wait" should check
to make sure that the resource it is waiting for is indeed available
to it before proceeding.

It is best to have exactly the right number, in exactly the right
places. Throwing in extra notifications in hopes of avoiding problems
is at best imprudent. It is difficult enough to write and maintain
reasonably bug-free multithreaded code when you have a good idea what's
going on -- it's hopeless when you don't.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top