473,805 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13563
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 misunderstandin g 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.c om...


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
2831
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, so maybe there is something else of wrong. Using the example 2 in the libpq chapter on "Postgres Programmer's Guide" as template i write :
2
4718
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 jobs and beeing able to be notified when each of these threads finished it's job.
4
2211
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 notification from libpq (PQnotifies), each client proceeds to execute a query for the last five records in the timeclock table. SELECT * FROM timeclock ORDER BY touched DESC LIMIT 5;
4
7083
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 never could find any answers in the e-mail nor in the documentation. Perhaps I just missed it. I have tried the following code snipit: Connection db = DriverManager.getConnection(url, user, passwd);
3
2139
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 seem to be totally case insensitive: free4testing=# select version(); version
5
3429
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 an hour), and almost never update each others data (less than once a day). The TCL-based replication project for multi-master is
5
7563
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) exceptions : (or u can download it from : http://www.geocities.com/mndt_0/files/WaitingForThread.java at this link it has the spaces )
3
1621
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
3491
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 allows a commuter to pass easily while a cash booth creates a wait line. The wait line is expected to wait for the 5th commuter to pass before any commuter on the wait line can pass through the toll booth. This is where my problem lies. All the...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.