Why do we need to take a lock before invoking wait()/notify() on an Object?

Hi,
Why do we need to take a lock before invoking wait()/notify() on an Object? i know that we shud take otherwise illegalstateexception is thrown.
what is the reason to take a lock bfefore invoking the above methods. why does jvm expects from the programmer?

Please do not crosspost..

Similar Messages

  • Why do we need to take a lock before invoking wait()/notify() on an Objec

    Hi,
    Why do we need to take a lock before invoking wait()/notify() on an Object? i know that we shud take otherwise illegalstateexception is thrown.
    what is the reason to take a lock bfefore invoking the above methods. why does jvm expects from the programmer?
    Cheers,
    duggana.

    Well, very often a wait or notify is conditional on the state of some flag (semaphore) which is protected by the monitor. By putting the wait in a synchronized section you guarantee that the sempaphore won't change between the final test of it and the actual wait or notify, otherwise a notify might be lost and the program hang.
    // wait on semaphor
    if (!canProcede)
       synchronized(this)
           if(!canProcede)
              wait();
    //   release semaphor
    synchronized(this)
         if(!canProceed) {
              canProede = true;
              notify();
        }If the wait above wasn't guarded by the sychrozined it's possible the second code fragment might be executed between the test and the wait, in which case the wait would be called after the notify and, hence, wait for ever.

  • Why wait() is there in Object class why not in Thread class

    why wait() is there in Object class why not in Thread class .
    while we use wait() in the case of thread environment?
    If there is any situation where we use it without using threads please mention with example. or link to that example..

    839091 wrote:
    The question still remain un-answered as the answers provided are not clear. Can anybody explain why wait(), notify() methods are available in Object class and not thread?What part of the answers given did you not understand?
    Have you even tried writing any code that uses wait/notify and thought about how you'd write the same code if they existed only on Thread rather than on Object?
    Have you studied the basics of Java's multithreading?
    Do you know what a lock is?
    Do you know what the synchronized keyword does?
    Do you understand the relationship between synchronized and wait/notify?
    If you can answer yes to these questions, then the reason that wait/notify exist on Object should be obvious. So, which of the above are "no"?

  • Terminal Server Session Management: why do we need a rdp session to take control of a terminal session?

    Hi all,
    As title, I have this question: why do we need a rdp session to take remote control of a terminal server session?
    I copied tsadmin and related file to a windows 8.1 pc and I'm able to see for every terminal server the list of users logged in, but the option "take control" is greyed out... why? is not possible to avoid this block?
    Thanks in advance
    Davide

    Hello, Davide_ita.
    Also tried to use RDSM to "Remote Control" user's sessions, but in this thread
    Remote Control
    with Remote Desktop Services Manager - error Access is denied (Windows Server 2012 R2)
    I get the recommendation to use RDP or Remote Assistance.
    The quote of
    TP []:
    Hi,
    You cannot remote control a session on a 2012 R2 RDSH server using Remote Desktop Services Manager.  You need to use the RDP 8.1 mstsc.exe or the RDS gui in Server Manager on 2012 R2.  The command you would use with the RDP 8.1 client would be
    this:
    mstsc /shadow:<sessionid> /control
    -TP

  • Why does my iPad Air takes a long time to charge?

    Why does my iPad Air takes a long time to charge?

    You need to provide more detail. What do you mean by "a long time?" Are you charging it plugged into a wall socket?
    Barry

  • Why does my iPhone 5 take very grainy flash photographs in the dark will a hard reboot be safe to do to try to fix or is it a hardware issue?

    Why does my iPhone 5 take very grainy flash photographs in the dark will a hard reboot be safe to do to try to fix or is it a hardware issue?
    And By hard boot I mean holding the home and power button down at the same time for 10 seconds or whatever
    I see other people have these grainy flash photographs if you try to take a picture in darkness the picture comes out very dark and grainy I thought the software would ultimately fix this but it's been going on for over a year I usually take my photographs in daylight but I need this to be fixed
    If it is a hardware issue I hope Apple will replace my iPhone 5 because I was just waiting for one of the iOS updates to fix it I bought my phone in November 2012 its the iPhone 5
    Please help or advise if you can was this just a software or hardware issue I know Apple was aware of it but I was advised that iOS update would fix it but obviously not
    Is it safe to do a hard boot on my iPhone five by holding the power and home button at the same time for 10 or 20 seconds I saw someone said that fixed there's at least temporarily
    I'm typing this on my iPhone five right now why do the words go off to the left and right no matter if I hold the phone vertical or horizontal the words bleed off to left right so for me to proofread it I have to move my text left to right to proof read it
    Thank you

    The flash on a smartphone camera is tiny. It only lights up a very small area right in front of the camera. It won't light up the whole scene.
    Have you seen the size of the flash on a professional camera? Even they can't light a whole scene in the dark.
    Fact is, a smartphone camera is not capable of taking good photos in the dark, even with the flash.
    You'll need to buy and learn how to use a professional, dedicated SLR camera to be able to take good photos in the dark. It is not easy.

  • Why do I need to return the old part, if I purchase a new part?

    Well, I had a problem with my motherboard, and got it replaced by an on-site tech HP sent me.
    The notebook is well out of warranty, aand I paid for the new motherboard+labor.
    However, when the tech showed up, he said he won't replace the motherboard unless I give him the old motherboard. He went on to say that this was the "company policy" and he won't let me keep any old part even if I pay for the new part.
    I was too tired t o argue with him, and he replaced the motherboard, and took away the old motherboard.
    On second thought, this is pretty absurd.
    It's like HP telling me "If you purchase a new HP notebook, you'll have to return your old HP notebook back to us".
    It would make sense if I was getting a free replacement and the notebook was under warranty. It doesn't make any sense when the notebook is out of warranty and I'm paying for the replacement part.
    Think of it, when I purchased the notebook, i obviously paid for the motherboard that came with the notebook. So why does HP get to take it away from me?
    If I purchase a new battery from HP store instead of amazon, do I need to return my old battery to HP?
    If I purchase a new keyboard from the HP store, do I need to return my old keyboard?
    I can give you the case number if you want.
    Honestly, if this is the "company policy", I won't ever bother with another HP product again.
    This question was solved.
    View Solution.

    HP only has new motherboards. They sell the bad ones into the Chinese market and they show up on eBay and similar places. You have a new motherboard. If you can tell us the part number of what you bought we can tell you the "full" price and the "exchange" price of the part. They should definitely explain the options to you but I think they likely assume you want the lower exchange price. 

  • Precautions i need to take when changing the Character set

    Hi,
    ORACLE VERSION: 10G Release 1 (10.1.0.3.0)
    I am going to change my database's characterset from AL32UTF8 to WE8MSWIN1252 character set and AL16UTF16 NCHAR character set. So i have few questions for you.
    1. What is the difference between Character Set and National Character set? Do i have to set both?
    2. What are precautions that i need to take while changing the characterset?
    3. What are JOB_QUEUE_PROCESSES and AQ_TM_PROCESSES parameters in Plain English? Why do i have to set these parameters to 0 as mentioned in this post below.
    Storing Chinese in Oracle Database

    1) The database character set controls (and specifies) the character set of CHAR & VARCHAR2 columns. The national character set controls the character set of NCHAR & NVARCHAR2 columns.
    2) Please make sure that you read the section of the Globalization manual that discusses character set migration. In particular, going from UTF-8 to Windows-1252 is going to require a bit more work since the latter is a subset (and not a strict binary subset) of the former.
    Justin

  • Why do I need to Clone a drive partition...

    ...if I'm installing a new OS to another one??
    I've got Panther--my current, albeit outdated, boot OS--installed on one partition of my Dual G4 (and yes, the limitations of this computer is one reason I'm not on Leopard yet)--and trying to install Tiger onto the 2nd partition (which will hopefully tide me over until I upgrade to a new iMac or Powerbook w/ Leopard). I don't have much experience upgrading to a new OS while one is working, so hopefully the older/current one will act as a backup safeguard if the newer one acts up.
    Anyway, I haven't been able to install it yet--for whatever reason, it's not progressing beyond "Verifying Destination Volume," and I can't seem to verify the partition in Disk Utility due to Authentication issues, but that's ANOTHER issue--but unless that directly relates, I can't figure out WHY everyone keeps telling me that I should clone either drive (using Carbon Copy).
    I already have all the important PERSONAL files from the current boot partition--and everything on the 2nd partition I'm trying to install to--backed up onto an external.
    So why do I need to clone either drive?? Just trying to clarify here...

    phasmatrope:
    I installed the new OS, Tiger, last night (which was actually fairly easy too... although it DIDN'T ask me if I wanted to do a Clean Upgrade, or an Archive & Install, which I'd heard were both options, which DOES worry me somewhat... but I suppose that's another post). It seems to be working fine thus far.
    It is hard to tell exactly what installation option was used in your installation, but it you are satisfied that your installation is working as it should, I don't think you need to be concerned about it.
    I figure in a few weeks, I may try deleting the clone from my partition (how long I should wait though, and whether or not I'll need to erase the drive entirely
    So long as your installation is working well, and all your data that you backed up has been restored, and you are sure you will not be losing anything of value, you may delete the clone/backup...but wait until I respond to another of your questions.
    what I'm wondering is: can I copy other material to that drive in the meantime without any problem?? After all, it IS a 300GB drive, and since I'd only cloned the 37 or so GB of my old boot partition there, I should be able to fit the 45 GB that are on the second partition onto there.
    I suggest that you partition your 300 GB external HDD so that it can accomodate all your needs.
    • Partition your HDD so that one partition is approximately the size of your internal HDD. Then you can clone your new installation to that partition, and make regular backups to that partition.
    • You can create a second partition to accomodate the material of the second partition of the drive you clone. Give yourself sufficient room for expansion.
    • Create other partitions one possibly just for scratch, saving odds and ends or whatever.
    Here is a step-by-step procedure for partitioning:
    Formatting, Partitioning Erasing a Hard Disk Drive
    Warning! This procedure will destroy all data on your Hard Disk Drive. Be sure you have an up-to-date, tested backup of at least your Users folder and any third party applications you do not want to re-install before attempting this procedure.
    Formatting an External HDD
    Connect external HDD to computer
    Turn on external HDD
    Start up computer and log in
    Go to Applications > Utilities > Disk Utility and launch DU.
    Select your HDD (manufacturer ID) of drive to be partitioned in left side bar.
    Select number of partition in pull-down menu above Volume diagram.
    (Note 1: One partition is normally preferable for an internal HDD. External HDDs usually have more than one. See Dr. Smoke’s FAQ Backup and Recovery for tips on partitioning external HDD
    Note 2: For more partitions than one, after you have selected the number of partitions you can adjust the size of the partition by selecting the top partition and typing in the size; then move down if more adjustments need to be made..)
    Type in name in Name field (usually Macintosh HD)
    Select Volume Format as Mac OS Extended (Journaled)
    Click Partition button at bottom of panel.
    Select Erase tab
    Select the sub-volume (indented) under Manufacturer ID (usually Macintosh HD).
    Check to be sure your Volume Name and Volume Format are correct.
    Optional: Select on Security Options button (Tiger) Options button (Panther & earlier).
    Select Zero all data. (This process will map out bad blocks on your HDD. However, it could take several hours. If you want a quicker method, don't go to Security Options and just click the Erase button.)
    Click OK.
    Click Erase button
    Quit Disk Utility.
    Please do post back with further questions or comments.
    Cheers
    cornelius

  • Why do I need to use a CMYK profile?

    Hi all,
    I am new to these forums, but have some theoretical and a bit of practical knowledge on Color Management. I know what a dot gain, color space, true black vs composite black, etc are, yet I struggle to build the big picture of the whole thing. I am actually doing design work, where we are going to print a brochure. I have done the Illustrator artwork, it has an embedded image and I am trying to make it ready for a good precise print.
    My question is, why do I need a CMYK profile at all??
    As I understand it, my document IS CMYK already, i.e. it uses component C, M, Y and K numbers for artwork primitives, and as far as I can understand the whole point of working with CMYK instead of RGB (which is for additive colorimetry - i.e electron guns and LCDs) is the fact that it is suitable for printers. If Cyan, Magenta, Yellow and BlacK inks get input from the CMYK numbers, then the print should look the same on all ink-utilizing devices, should it not?
    That said, I understand the point of RGB-to-CMYK conversion and vice versa, since obviously i have to preview my art on my monitor before it gets into printing. But since CMYK profiles exist, does it mean printers printing the same CMYK values get different results? (disregarding issues of different paper weights and dot gains)
    Thanks. This has been bugging me, and I am not THAT much into printing yet as to buy the Real World Color Management book i ve been hearing so much about.

    If I may add,
    The ONLY times most of us need to embed an ICC profile in a CMYK file are:
    1) We want to PROOF it faithfully on a hardware-calibrated monitor (Photoshop reads the embedded profile and Converts it to Monitor RGB).
    2) We want to PROOF it faithfully on any other hardware-calibrated printer that uses a different Target color space (Photoshop reads the embedded profile and Converts it to the specific target profile). (Or the workflow ignores my Source Profile and Converts to target proofing space based on the wrong working space).
    3) We need to CONVERT it to another profile (Photoshop reads the embedded profile and Converts it to a new target space/profile).
    PERSONALLY, when I deliver CMYK it is already Converted to the correct CMYK (directly from my 16-bit Adobe RGB file), and I do not want anyone downstream dinking around with My Color.
    The old Quark did this task nicely -- simple place the tif and print the job.
    Today's pdf and color-managed layout programs make understanding and implementing this instruction much more confusing and hazardous (how to send 'the numbers' straight through).
    If I trust the print shop 100%, I will hand them my 8-bit Adobe RGB and let them do the Conversion to their press CMYK.
    Otherwise, send [my] CMYK 'numbers' straight through. Period.
    +++++++
    The problems with people who do not understand HOW ICC profile work is they will strip my profile (knowingly or unknowingly) and Assign-Apply-Assume their own profile -- effectively -- hosing my color.
    This problem is easy to see in Photoshop by Assign profile.
    The classic real-world example is the old-school print shop's clueless "color expert" who ignores our embedded profile, because he says, he has turned "color management off" and "doesn't use profiles." He tells us our file is bad because his print is bad, and he will try to correct our bad color and print another round of proofs.
    Does this sound familiar?
    What the cave man actually did was strip our embedded file of its profile, and/or he Applied-Assumed-Assigned his own working space to our file then he takes a sledgehammer and beats our color up into his closed workflow (and he is probably working on an uncalibrated monitor to boot).

  • Why does Bridge Need Illustrator to Save as PDF compatible file?

    1. Why does Bridge need Illustrator files to be saved as PDF files? "PDF Compatible File" ticked in the save menu.
    2. Why does saving with this info take so long, even on decent fast modern systems?
    3. Why does Bridge not consistently render the Illustrator files in FULL RESOLUTIONS, seemingly shooting for half resolution much of the time, and simply stopping at that?
    4. Why does "clicking" on the preview inside Bridge bring up the full resolution?
    5. How do I shortcut this process so that every file is previewed in Full RESOLUTION, instantly?
    What is the point of Bridge?  What's its reason for existence?
    First time user of Bridge.

    Since someone is bound to say that this should be asked in the Bridge section... it already is.  And has been referenced back over here.
    You can find it here:
    http://forums.adobe.com/message/5655632#5655632
    Answer wherever you see fit, if you're up to the task of dealing with someone attempting to have a broader view, perhaps also suffering from somewhat objective analysis that sometimes contains direct criticism of the way Adobe does things.

  • Why do I need a second java.exe when I alreayd have another in a JDK instal

    When I install JDK then there are two instances of java.exe
    (and other programs like javaws.exe). One instance in
    INSTALL_DIR\bin\
    and the other in
    INSTALL_DIR\jre\bin\
    So why do I need two exes instead of one?
    Peter

    Hello!
    So why do I need two exes instead of one?Don't know the reason myself, ask the developers..........
    One instance in INSTALL_DIR\bin\
    and the other in
    INSTALL_DIR\jre\bin\Yes, checked that, you are right.
    But , whats the problem, It hardly takes 2MB more space.
    Or, were you implying that ideally java.exe and javaws.exe should not be in "INSTALL_DIR\bin\" as they are involved in running the java programs.
    Thanks!

  • Why does m4v need to be converted again

    Hi. I converted a dvd movie I bought into the ipod format .m4v using another converting software program I have. I then imported it into the videos section of my itunes. It would not load into my ipod unless i convertd it again using the itunes conver for ipod option. Why does this need to be converted again for ipod if its already in a .m4v and is there any way i can fix this so when im originally converting my movie with my converting software I can eliminate this last step in itunes. It takes up to 5 hours to convert in itunes. thanks

    I should also add that I am using a AVS video converter which has an IPod 5.5 converting option that makes my movies Highest available quality H.264, 30fps 640x480
    There are more Ipod options availble but im using the Highest quality available one. Maybe I should be using one of these:
    ipod 5x- NTFS Standard quality H.264 29.97fps, 320X240
    ipod 5x- PAL standard quality H.264 24fps, 320X240
    ipod 5x- low quality H264., 20fps, 320X240
    ipod 5x - Best quality (MPEG4, 24fps, 320X240)
    ipod 5x- economy quality (MPEG4, 20fps, 176X144)
    ipod 5x- for tv output (MPEG4, 24fps, 512X384)

  • Why Do We Need Constructor With Arguments?

    I understand that constructor is used to create instances.
    We can have constructors with 0 argument or with one/multiple arguments. Why do we need a contructor with arguments? What is the purpose of doing it?
    Thank you for your help.

    There are three general ways to provide constructors, like you said:
    1) Default constructor (no arguments)
    2) One or more constructors with arguments
    3) One or more constructors with arguments as well as a default constructor
    From a design standpoint, the idea is to give as much information needed for constructing an object up front. Look at the standard Java API for some examples (and because I couldn't find a standard class with just a default constructor, one made up):
    public class Foo {
      private long createTime;
      public Foo() {
        createTime = System.currentTimeMillis();
      public String toString() {
        return "This object was created at " + createTime;
    }This code has no reason to take any arguments. It does all construction on its own and already has all the information it needs. On the other hand, look at BufferedReader. There's no possible way this object can ever be constructed without an argument. What's it buffering? It doesn't make sense to ever instantiate new BufferedReader(). It'd be useless. So BufferedReader has no default (no-arg) constructor.
    Sometimes (very often in Java) you want to do both. Let something be instantiated with no arguments, but also provide the option of creating something with more specific details. A good example is ArrayList, which has three constructors:
    public ArrayList() --> Construct an empty ArrayList with the default initial capacity;
    public ArrayList(Collection c) --> Construct an ArrayList populated with the contents of another collection;
    public ArrayList(int capacity) --> Construct an empty ArrayList with a specific initial capacity.
    Sometimes it makes sense just to use the default. Sometimes you want more control over the behavior. Those are the times to use multiple constructors.
    Hope this helps!

  • Why do we need account key in SD revenue account determination?

    Hi,
    Why do we need account keys in SD pricing procedure and revenue account determination? If we dont use account keys wht will be the problem in priding procedure and revenue account determination?

    hello, friend.
    account keys allow you more flexibility in assigning revenues, costs and other financial data to different GL accounts.
    let us take, for example, surcharges and discounts.  surcharges are extras charged to the customer for maybe freight, penalties and other services.  discounts could be header or item related, and can take many forms (volume discounts, customer discounts, customer group discounts, etc.).
    in SAP standard, condition types in pricing procedures that are surcharges (i.e. freight)  are assigned to account key ERF.  discounts are assigned ERS.  when you do account determination, it can look like this:
    condition type KF00 (freight), account key ERF, post to GL account 600010.
    condition type K007 (discount), account key ERS, post to GL account 700010.
    however, your company might want the different surcharges to be posted to different GL accounts.  let us say your company wants you to define additional freight surcharges KF01 and KF02.  the company also wants you to post these to separate GL accounts.  so now, you define additional account keys ZF1 and ZF2.   you then assign these to the condition types in the pricing procedure, and then do account determination as follow:
    condition type KF01, account key ZF1, post to GL account 600020.
    condition type KF02, account key ZF2, post to GL account 600030.
    these are just some impact of account keys.
    hope this helped you.
    regards.

Maybe you are looking for

  • I bought an app, and it doesn't run

    I downloaded a pay app, " Gastos Celular " , and it doesn't work. When I try to open it, it just shows the app for a second and then, the app shutdown. I restarted my iphone 5, and try to reinstall the app, but nothing change. I wonder if apple can g

  • Unix socket

    We are writing application that have more then one processes and we are planing to use Unix socket for communication between the processes, and my questions is 1. is there any performance issues with Unix socket ( the message size will be something b

  • Opportunities Load  via IDOC in CRM

    Hi Guys I am trying to load opportunity via IDOCS. I am using the message type CRMXIF_ORDER_SAVE_M01. The only problem I am facing is to get a reference lead ID in the Opprtunity. In easy access the reference lead number is inputted on the details pa

  • Set default result in interaction record

    Hello gurus, Could you  please share any idea how it is possible to set default Interaction Record result? By default it is blank and user needs to select the value from the list on the IR page, but it is not convinient. Unfortunately I can't find th

  • Where is the application downloaded

    Hello, I have tried out the demo's for web start. As I understand it, the applet is downloaded onto my computer before it is opened in the web browser. But I can't seem to find where the applet was downloaded. How does it know where to put the files?