sleep() versus wait(obj) performance

I have a multithreaded app where threads pause for a certain amounts of time. In some cases I also wake them up part way through the process.

Is using Object.wait() a more expensive operation than Thread.sleep() when using them for a threading pause? I.e. memory or processing costs... etc.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you want to pause for a certain amount of time (as you say), then you should use Thread.sleep(), since that has the ability to provide the amount of time to wait (depending on how accurate you want it).

In both cases, processing costs are approximately the same because the thread is taken out of the execution queue.  I'm not sure of the differences with regard to memory usage.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sleep will just pause for the speified time.
wait allows you to pause, and get restarted when some other thread "notifies" that the situation may have changed. Depending on your situation, the latter may be more efficient.
jkelly061597Author Commented:
I know the abilities of each. I am looking for performance information.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

jkelly061597Author Commented:
Possible question: Are they implemented in the JVM in a way that makes one worse off than the other?
I suspect that both Wait and Sleep behave the same way about counting the time before they resume control of the Thread.  However, since Java isn't meant to be a real-time langauge, I suppose there could be variances between different JVM implementations and also about how each method is naitivly implemented within the same JVM.  Best bet about getting performance information is to conduct tests on your own with a program that performs calls on both Wait and Sleep and logs the data.
neithe sleep nor wait 'count time'  they just hang themself up in a que designed for processes 'waiting for a time interrupt' after telling the system when they want the interrup.

wait has some slightly more complex admin-chores to do because it can also be reactivated by a notify.

The difference is miniscule though. If your appication is so timecritical that it matters you should probably be using C or C++ instead.
>> If your appication is so timecritical that it matters you should probably be using C or C++ instead

Just what I was thinking ;-)

Also, if the general principle is that the pause should occur for a specific amount of time, you'll need extra code (eg. a Timer) in order to manage the wait/notify anyway.
jkelly061597Author Commented:
Thanks everyone,

Just FYI: This is not a time critical app, but a performance critical app so I'm just checking.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.