473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

notify() and wait()



notify() and wait() throw an exception if the calling thread does not
own the object's monitor. Does this imply that the check is made at
runtime, and if so, why can't it be made at compile time?

TIA,
ves
Sep 14 '05 #1
2 13551
On Wed, 14 Sep 2005 02:55:08 GMT, Vespasian <ve*@ves.net> wrote or
quoted :
notify() and wait() throw an exception if the calling thread does not
own the object's monitor. Does this imply that the check is made at
runtime, and if so, why can't it be made at compile time?


Threads don't exist at compile time. At compile time, you have
absolutely no idea how many threads there will be or which threads are
contending for access to which objects.

The very fact you asked this question indicates there is something
very basic you are misunderstanding about threads. Unfortunately, I
don't know what your misconception is. I suggest reading up in a text
book on them, or at least reading my introduction to them at
http://mindprod.com/jgloss/thread.html

IF you have assembler background, I could tell you that each thread
has it own call stack and local variables stack, about a meg of
overhead. On a multicpu machine it can run simultaneously with other
threads. On a single cpu machine, there is timeslicing to give each
thread a short burt of CPU time, then it stops in mid flight and lets
another thread have a go. Each thread has its own set of hardware
registers including instruction pointer.

When threads use local variables there are no problems since they are
private to the thread. But when they use objects or instance or static
variables there is the potential of other threads accessing them at
the sime time. That is when you use synchronized to limit access to
one thread at a time to accessing an object.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Sep 14 '05 #2
Yes, it is checked at runtime. Doing the check at compile time would be like
asking the complier to check if any division arithmetic throughout your
program (e.g. a / b) would result in a divide-by-zero error! Not easy.

"Vespasian" <ve*@ves.net> wrote in message
news:s4********************************@4ax.com...


notify() and wait() throw an exception if the calling thread does not
own the object's monitor. Does this imply that the check is made at
runtime, and if so, why can't it be made at compile time?

TIA,
ves

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alessandro GARDICH | last post by:
Hi to all I have problem with NOTIFY/LISTEN ... I'm writing a C++ application with libpqxx, I thought was a problem of the lib but I try also with a C program using libpq with the same result,...
2
by: objectref | last post by:
hi to all folks, i want to create the following senario: i have a T1 (Thread 1) that acts like http server that receives incoming requests. From that T1, i want to spawn from T1 to Tn thread...
4
by: Joe Lester | last post by:
I'm using PostgreSQL 7.4.1. I have 140 clients connected on average using libpq. When one client sends "NOTIFY timeclock;" to the server all 140 clients are listening for it. After receiving a...
4
by: Glenn Sullivan | last post by:
Hi, I have been trying to get LISTEN/NOTIFY working in with JDBC. I cannot seem to get notified. I looked in the e-mail archive and saw a lot of similiar questions a couple of years ago. I...
3
by: Frank van Vugt | last post by:
L.S. Either the docs or I are missing something.... While using libpq I noticed that listen/notify calls were being converted to lowercase. A further look showed that the listen/notify calls...
5
by: Ted Shab | last post by:
Hi, I'm trying to come up with a relatively simple multi-master replication solution. This is for multiple databases that need to be discreet, and change relatively infrequently (10-30 updates...
5
by: cozsmin | last post by:
hello , as u know wait() and notify() will not thow an exception if the method that calls them has the lock , or esle i misundrestood java :P this is the code that throws (unwanted) ...
3
by: Lateef | last post by:
i am learning java. in multithreading i want to put a thread to wait() and then call back it by notify() .. but i am not able to do so. can any one explain it to me by simple example..
2
by: greyradio | last post by:
I've recently have been given an assignment to do and it seems that notify() does notify() any of the waiting threads. The project entails 10 commuters and two different toll booths. The EZPass booth...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.