Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java Newsletters Archive: 152

JavaFAQ Home » Java Newsletters Go to all tips in Java Newsletters


Bookmark and Share
Issue No: 152 6 March 2003
11823 subscriber

"...if you have no mentors around in the initial stages."
"This book has saved me hours of research...""


Foreword: Excuse me for possible mistakes. English is not native language for me.

In this issue:
  • 1. When should I use notify() and when notifyAll() methods on threads?
  • 2. The clear-Method in the java.util.Calendar-Class doesnt behave like I suggest.
  • 3. Latest posts on our message board
  • 4. Link to Java FAQ

  • Hello dear friends!

    Have you entered yet?

    JavaFAQ.nu is proud to announce that we are a sponsor of the March 6 Amber Taylor IT Give-Away promotion. We do not do this very often but thought you would be interested in the products and services for IT Professionals being awarded. There is something for everyone! What is the cost? Not a thing! Enter here. You could win a free 500 Java Tips eBook.


    Tip 1

    Question: When should I use notify() and when notifyAll() methods on threads?

    Answer: Generally it is more reliable to use notifyAll() method. Notify() method wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods. Since it is internally implemented we do not know exactly which thread will be chosen.

    This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
    By executing a synchronized instance method of that object.

    By executing the body of a synchronized statement that synchronizes on the object.
    For objects of type Class, by executing a synchronized static method of that class.
    Only one thread at a time can own an object's monitor.

    It is much safer to use from the beginning notifyAll() method and later trying to optimize your program you can try to switch to notify(). You have no idea which thread will be awakened. You must be sure that every waiting thread will be able to continue if you use notify() method. The behavior of your program will be more predictable.
    From another hand using notify() method will decrease CPU and memory consumption since just one of multiple thread is awaken and rest are in waiting mode.


    50%-75% OFF Ink jet cartridges!. Please save money...(click here)


    Tip 2

    Question: The clear-Method in the java.util.Calendar-Class doesnt behave like I suggest. I want to clear the hour-field in a Date. If I use Calendar.clear(Calendar.HOUR) the hour is not reset. If I use Calendar.clear(Calendar.HOUR_OF_DATE) the hour is not reset also. Only if I invoke both methods the hour is reset. (java version "1.2.2")

    Answer: It is known Java bug.
    Call cal.clear(cal.HOUR) as well as cal.clear(cal.HOUR_OF_DAY).
    Or
    Call Calendar.set(Calendar.HOUR_OF_DAY,0) instead of Calendar.clear
    (Calendar.HOUR_OF_DAY).
    This bug is not fixed yet...


    Latest posts on our message board

    gzip file
    Hi!

    I need help again, how no! I'm writing an application which generate SVG files. I want to compress this files to use the .svgz extension. I know that it possible use gzip to compress the file, but I wonder if I can use some Java class to do it.

    I have tried this code...


    Please Help!!!!
    I have to design a simple prototype interface that performs a simple control function. The function is to control a robot which moves up, down, left and right. It only has to be a simple interface which operates from the command window but it needs functionality as people have to test it work. Can you offer me any suggestions on coding for this as I'm really stuck, thank you.
    Please answer here


    Save an image-object as image on the web server..
    For a little kids-homepage I have written an applet, within you can "paint" with the mouse. But now I want to store the image on the server. There is a cgi-script I can call to upload a file (i.e. http://domain.com/cgi-bin/store.cgi?file=image.jpg). How can I do this from the applet? The problem is that I haven't a file "image.jpg" that I could send. In the applet there is only an Image-object. Is it possible to save the file via the cgi-script? Can anybody point me in the right direction?


    Problem while trying to make an executable with Jexegen
    Hi,

    If have downloaded MS SDK for Java 4.0 and I wanted to make an executable. After reading some documents about Jexegen I have to typed this:

    jexegen /main:Studieresultaten /out:Sresult.exe /w /v *.class

    Looking at the details I can see that all the classes has been added. But I always get the following error:

    Warning: Main class specified but main class file was not found.

    Weird, because Studieresultaten.class has been added!!!!

    I have searched on Google for this error, but I can only find either a post that has not been replied or a Chinese post.
    Can anyone help me???


    Importing .swf Flash file into Java Application
    AS far as I understood there is a Java package that is for supporting Java and flash collaboration ))
    For example how can I import flash file into Java application(standalone) or sending information from Java to Flash and opposite.
    Please tell what the package is and where can I download it from.


    movable disks
    Hi,

    I would like to make a JFileChooser that finds the directory to the movable disk. How shall I do?

    JFileChooser chooser = new JFileChooser( new File(xxxxxxxxxx) );

    Please answer here...


    Please ask your questions and help each other at our Java Forum:
    http://javafaq.nu/forum/


    The Java FAQ Daily Tips is a newsletter that is only sent to those who have specifically subscribed to it (double opt-in).

    To subscribe/unsubscribe to "The Java FAQ Daily Tips" weekly edition newsletter visit our page here:
    http://www.javafaq.nu/plm2html/my_subscription.shtml

    If you have troubles please contact us: subscription@javafaq.nu


    Link to Java FAQ

    If you have added a link to http://javafaq.nu on your WEB-site, please let us know and you will get listed on our
    "pages linking to us" pages! If your page is a programming is programming relates you will of course get listed in the WEB-directory as well. Also, if you link to us, you have a chance to be listed in this newsletter as well.

    More information and graphics artworks can be found here
    http://javafaq.nu/other/linktous.shtml


    Advertising

    For information on advertising on the Java FAQ's Daily Tips Newsletter, send an email to: adv@javafaq.nu
    You will get the answer immediately from autoresponder!


    Send your comments, questions, praise and complaints to us: comments@javafaq.nu

    Copyright (c) 2000 - 2003 John Andersson, All rights reserved.


     Printer Friendly Page  Printer Friendly Page
     Send to a Friend  Send to a Friend

    .. Bookmark and Share

    Search here again if you need more info!
    Custom Search



    Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

    RSS feed Java FAQ RSS feed Java FAQ News     

        RSS feed Java Forums RSS feed Java Forums

    All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

    Interactive software released under GNU GPL, Code Credits, Privacy Policy