Why notify/notifyAll method doesn't resume the waiting thread quickly?????

I am currently working on a socket based IM server, I get messages from multiple clients simultaneously and put them into queues, for each queue in my server I have a separate listener running in a thread, as soon as a packet comes in the queue (from any client) it��s related thread is notified to get that packet from thread and process it.
Here I am using wait/notify blocking mechanism to control loop in my listener thread. My logic works like this
1)     When Listener thread starts it calls the synchronized getNextPacket method on that queue if the queue has any packet (i.e. it��s length is greater then zero) then it will remove that packet from the underlying vector (NOTE: I am using Vector to contain packets) and return that packet to listener thread, else if queue doesn��t have any packet (i.e. its size is zero) then I will call wait() method which causes the listener thread to wait.
2)     Now when any client adds some packet in that queue using synchronized addPacket( ) method I first add that packet in the underlying vector and then call notify()/notifyAll() to awake that listener thread, which again calls the getNextPacket() method and this cycle continuous like this.
So multiple threads (clients) are adding data in the queue using synchronized method, only one listener thread is getting data from that queue using a synchronized method again �� .
This approach works fine but sometimes I have noticed that the listener thread doesn��t resume just after notiy() / notifyAll() has been called , sometimes it resumes after a long time sometimes it even don��t resume (after waiting a long time I assumed this).
Solutions I tried
1)     I did set the listener Thread��s priority to Maximum but facing same problem again.
For better understanding I am also sending you the code for my queue class and it��s listener thread.
CODE OF QUEUE CLASS
import java.util.Vector;
import org.apache.log4j.Logger;
import com.tcm.unicorn.server.UnicornCustomeObject;
* @author sajjad.paracha
public class UIMPCommandsQueue {
     private static final Logger logger=Logger.getLogger(UIMPCommandsQueue.class);
      * Contains all the packets from clients
     private Vector <UnicornCustomeObject> unicornCustomeObjectQueue = new Vector<UnicornCustomeObject>();
     private UIMPCommandsQueue(){
     private static UIMPCommandsQueue uIMPCommandsQueue = null;
     public static UIMPCommandsQueue getInstance(){
          synchronized(UIMPCommandsQueue.class){
               if(uIMPCommandsQueue!=null){
                    return uIMPCommandsQueue;
               }else
                    return uIMPCommandsQueue = new UIMPCommandsQueue();
      * Adds a new command
      * @param unicornCustomeObject
     public synchronized void addCommandPakcet(UnicornCustomeObject unicornCustomeObject){
          logger.debug("[[[[[[[[[[[[[[[[[[[[[[[[[[   Going to add a packet in queue  no "+unicornCustomeObject.getClientSession().getRequestQueueNo());
          unicornCustomeObjectQueue.add(unicornCustomeObject);
          //** Notify the Listener (RequestProcessor) Thread that a new packet has been arrived in the queue
          //** So it now can again start it's processing
          notifyAll();
      * Removes an object from queue whose processing has been started or completed
      * @param unicornCustomeObject
      * @return
     private boolean removeCommandPacket(UnicornCustomeObject unicornCustomeObject){
          return unicornCustomeObjectQueue.remove(unicornCustomeObject);
      * <p> If no packet is available in queue it retuns null value
      *     otherwise returns an object from that queue
      * <p>
      * @return unicornCustomeObject
     public synchronized UnicornCustomeObject getNextCommandPacket(){
          if(unicornCustomeObjectQueue.size()>0){
               UnicornCustomeObject unicornCustomeObject = unicornCustomeObjectQueue.get(0);
               logger.debug("[[[[[[[[[[[[[[[[[[[[[[[[[[   Got a packet from queue no  "+unicornCustomeObject.getClientSession().getRequestQueueNo());
               logger.debug("[[[[[[[[[[[[[[[[[[[[[[[[[[   Going to remove a packet from queue no  "+unicornCustomeObject.getClientSession().getRequestQueueNo());
               removeCommandPacket(unicornCustomeObject);
               return unicornCustomeObject;
          }else{
               try {
                    //** Force the Listener (RequestProcessor) Thread to wait for notification
                    //** This Thread will be only notified if a new command packet has been arrived(added) in the
                    //** Queue i.e in addCommandPacket Method
                    wait();
               } catch (InterruptedException e) {
                    logger.error("",e);
               return null;
CODE OF LISTENER CLASS
import org.apache.log4j.Logger;
import com.tcm.unicorn.server.UnicornCustomeObject;
public class RequestProcessor implements Runnable {
      * will listen on Request queue for any new massages
     public void run() {
               //** get an instance of RequestQueue before the loop  
               UIMPCommandsQueue requestQueue= UIMPCommandsQueue.getInstance();
               while(true){
                    try{
                         //**call the blocking method getNextCommandPacket()     
                         UnicornCustomeObject unicornCustomeObject= requestQueue.getNextCommandPacket();
                         if(unicornCustomeObject!=null){
                              System.out.println("Got a pcket will process it now.......");                    
                    }catch(Exception exp){
                         exp.printStackTrace();
Can anybody please tell me where I am doing something wrong and whats the best way to get rid of this situation .
Thanks in advance
Message was edited by:
meetsaju

Another question !
in my previous programe i have seen a starange behavior , my processor thread sometimes processes the later message before the message came before that in queue here is an output of my debug statements
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 10
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 11
INFO :03 May 2007 11:21:17,>>>>>>>>>>>>>>>>>>>>>>>>requestProcessorThread is in block state
INFO :03 May 2007 11:21:17,>>>>>>>>>>>>>>>>>>>>>>>>requestProcessorThread is in block state
INFO :03 May 2007 11:21:17,>>>>>>>>>>>>>>>>>>>>>>>>requestProcessorThread is in block state
INFO :03 May 2007 11:21:17,>>>>>>>>>>>>>>>>>>>>>>>>requestProcessorThread is in block state
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 30
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 13
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 0
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 12
INFO :03 May 2007 11:21:17,>>>>>>>>>>>>>>>>>>>>>>>>requestProcessorThread is in block state
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 20
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 40
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 31
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 14
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 15
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 32
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 33
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 16
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 34
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 17
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 35
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 18
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 36
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 19
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 37
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 41
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 38
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 39
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 42
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 43
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 21
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 44
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 22
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 45
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 23
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 46
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 24
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 47
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 25
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 26
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 49
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 48
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 27
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 28
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 1
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 2 look at the lines
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 49
INFO :03 May 2007 11:21:17,[[[[[[[[[[[[[[[[[[[[[[[process the packet no 48
as for as i know it shouldnt be the case as we are using a FIFO queue here....just querious how it is possible that a later message is taken from a FIFO queue.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Why my epson 3800pro doesn't center the print

    Hi,
    I have a interesting and very annoying problem. Why my epson 3800 doesn't center the prints on the paper anymore?
    Using this printer for more than two years now and all of the sudden regardless the paper size and the settings the i
    mages are centerd for an 8 1/2 x 11 ratio. Spent nearly 2 hours on the phone talking to Epson support repairing
    disk permission, uninstalling and reinstalling the printer, reconfiguring and so fort. Still, every print is off center.
    In the printer dialog everything seems fine; when seting up the printer and paper size the image on the screen
    adjust's accordingly but the print still comes out wrong. The technician on the phone suggested - maybe just wanted
    to get rid of me - that it's something to do with Photoshop.
    Anybody has  an idea what could be wrong?
    Thanks, Janos

    monkeyfighterz wrote:
    Anyhow, here are the images in question. As you can see from the settings am about to print on a Canson 11x14 paper.
    Which paper is it? I did a search on the Canson range and could not find an 11x14 paper. The closest I could find is 11x17, like the other paper makers. Did you cut the paper down to 11x14 yourself? If so, Tai Lao has a good question about whether the measurement dimensions of the cut paper are correct, it would be good to double-check.
    monkeyfighterz wrote:
    It made me think if there is a paper sensor (is there such thing?) in the printer not functioning?
    There is a paper sensor in the 3800 (I use a 3800 too, with no problems centering). The paper sensor is optical, and can be misled by existing ink on the paper. Especially black. Is your paper blank, or something already printed on it? If your paper is already printed with a significant dark area near the edge, the sensor might assume that the paper doesn't actually begin until it finds white. If this causes the printer to change where the print head starts on the paper, this can cause alignment problems.
    Tai Lao wrote:
    "Canson" (Canon?) paper
    I'm assuming it's Canson. Canson is one of the traditional European paper makers who have adapted some of their fine art papers for modern inkjet printing. Their product line has been around for about half a millenium.

  • Can someone tell m why my iPad 2 doesn't display the YouTube app? I'm so confused. It is a standard app n the original iPad.

    Can someone tell m why my iPad 2 doesn't display the YouTube app? I'm so confused. It is a standard app n the original iPad.

    Well you already know the answer, but it was not included in iOS 6. Google released an YouTube App for the iPad so you can download that in the App Store.

  • Wait() releases ALL of the waiting thread's monitors?

    When wait() is called from a synchronized bock, it is my understanding that the current thread releases the monitor it was holding (which was the monitor of the object that was being synchronized on.)
    What is confusing me is my testing of this code:
       public synchronized Object lock() {
          synchronized(lockObj) {
             if (bLocked) {
                try { lockObj.wait();}
                catch (Exception e) { e.printStackTrace(); }
           bLocked = true;
           return someObject;
       }When this method is called by Thead A and he has to wait, I can see where Thread A will release his lock of lockObj. However, the whole method is synchronized, (meaning, against this), and lock() is waiting and hasn't finished executing yet. I suspected Thread B wouldn't be able to call lock(), because Thread A should still have a monitor for this. But Thread B can- which must mean that when Thread A goes into wait(), he gives up all his monitors across the board, not just the one in immediate involvement (the one for lockObj, in this case)?
    P.S., forget what this code is supposed to accomplish- i wrote it trying to understand the monitor states.
    Thanks!

    I notice that the lock() method is not a static method. So everything depends on how you are testing this code sample. You haven't included that in your posting.
    What I suspect is:
    You are having your threads access two DIFFERENT instances of the object who owns the method lock(). This means that your threads are NOT competing for executing the lock() method on the SAME object.
    lockObj.wait() releases the lock on the lockObj ONLY. wait() does not release locks on all monitors owned by the thread executing the wait().
    What you are trying to prove can be understood easily by using static synchronized methods.
    If your lock() method is static synchronized, you will find that a Thread B can't enter the lock() method at all. Why? Because Thread A has only released the lock on the lockObj. It STILL holds the lock on the class level monitor. When did Thread A obtain this? When it entered the lock() method. Unless Thread A releases the class level monitor, by doing
    xyz.class.wait();
    in the lock() method, any other Thread B will simply wait to enter the lock() method.
    To carry the discussion further, when another thread, say Thread C, does a xyz.class.notify(), Thread B is woken up first and enters the lock() method. Thread A will return from the xyz.class.wait() only after Thread B quits the lock() method.

  • Why Data Services Validation doesn't give the right result in XML?

    Hi,
    I am struggling with a dataflow that contains the following:
    - an Excel as source
    - a validation transform that check a specific value in one of the excel columns. If the value is equal, the record goes to the pass path and if not, it goes to fail path
    - a simple query on the pass path with a row_gen that selects all passed records and send it to an XML file (using XML target)
    - a CSV target file on the fail path that gets the failed record from the validation
    The result is unexpected: both files contain the failed records.
    Now, if you modify slightly the dataflow and add another pass path to the validation, which has a CSV file as target, suddenly, the result is what you would expect:
    - The XML file on the 1st pass path (with the query) now contains the successful records
    - The CSV file on the 2nd pass path contains the successful records as well
    - The CSV file on the fail path contains the failed records
    If you create a dataflow that doesn't have an XLM file as a target, this issue doesn't seem to happen. I have made several examples with datastore and with CSV files. Somehow it seems there is something happening wrongly when the only target for a validation path (pass or fail) is an XML file.
    I can send the ATL for both examples above
    Could someone help me understand if I do something wrong OR if there is indeed a bug that should be addressed?
    Thanks a lot!
    Isabelle

    Hi Manoj,
    Thanks for quick reply!
    To answer your questions:
    - in the validation transform what is the value of Action on failure option - send to fail, send to pass or both ?
       send to fail only
    - is delete and recreate option checked for the target xml file ?
      yes
    - how many rows do you see in monitor log for pass and fail ?
       In the 1st dataflow, the monitor show the following where the pass number is 26!
    Path name State Row Count Elapsed time (Sec) Absolute time (Sec)
    DFW_TransformationUsingValidation_5/SpinFormat_1 STOP 28 0.047 0.699
    /DFW_TransformationUsingValidation_5/Validation STOP 28 0.000 0.699
    /DFW_TransformationUsingValidation_5/Split STOP 26 0.000 0.699
    -DFW_TransformationUsingValidation_5/FailValidation_TransformationUsingValidation_5.csv STOP 26 0.000 0.699
    /DFW_TransformationUsingValidation_5/Row_Generation STOP 1 0.000 0.699
    /DFW_TransformationUsingValidation_5/CacheSplit STOP 26 0.000 0.699
    /DFW_TransformationUsingValidation_5/CacheSplitMemoryReader STOP 26 0.000 0.699
    /DFW_TransformationUsingValidation_5/Validation_Pass_1 STOP 26 0.000 0.699
    /DFW_TransformationUsingValidation_5/Query-Nest1: 0 STOP 1 0.047 0.699
    /DFW_TransformationUsingValidation_5/Query-Nest1: 1 STOP 26 0.000 0.699
    /DFW_TransformationUsingValidation_5/Query STOP 1 0.000 0.699
    -DFW_TransformationUsingValidation_5/GUID::'5e0a492d-1452-4e0b-be37-758c2249b7a4' LOAD MESSAGE PassXM STOP 1 0.000 0.699
    In the 2nd dataflow, just by adding another pass path filling a CSV file, the number of pass records is 2:
    DFW_TransformationUsingValidation_5/SpinFormat_1 STOP 28 0.047 0.689
    /DFW_TransformationUsingValidation_5/Validation STOP 28 0.000 0.689
    /DFW_TransformationUsingValidation_5/Split STOP 2 0.000 0.689
    -DFW_TransformationUsingValidation_5/PassValidation_TransformationUsingValidation_5.csv STOP 2 0.000 0.705
    -DFW_TransformationUsingValidation_5/FailValidation_TransformationUsingValidation_5.csv STOP 26 0.000 0.705
    /DFW_TransformationUsingValidation_5/Row_Generation STOP 1 0.000 0.705
    /DFW_TransformationUsingValidation_5/CacheSplit STOP 2 0.000 0.705
    /DFW_TransformationUsingValidation_5/CacheSplitMemoryReader STOP 2 0.000 0.705
    /DFW_TransformationUsingValidation_5/Validation_Pass_1 STOP 2 0.000 0.705
    /DFW_TransformationUsingValidation_5/Query-Nest1: 0 STOP 1 0.047 0.705
    /DFW_TransformationUsingValidation_5/Query-Nest1: 1 STOP 2 0.000 0.705
    /DFW_TransformationUsingValidation_5/Query STOP 1 0.000 0.705
    -DFW_TransformationUsingValidation_5/GUID::'5e0a492d-1452-4e0b-be37-758c2249b7a4' LOAD MESSAGE PassXM STOP 1 0.000 0.705
    Edited by: Isabelle Thore on Oct 8, 2010 6:53 AM
    Edited by: Isabelle Thore on Oct 8, 2010 6:54 AM
    Edited by: Isabelle Thore on Oct 8, 2010 6:55 AM

  • Why my ipad 2 doesn't have the youtube built in as my ipad 1?

    I got the new ipad 2 and just found out that there is no youtube built in like my ipad 1. Does anyone know how to get it? When I got Ipad 1, it was on my screen without doing anything.
    Thanks
    Wanna

    http://www.apple.com/ipad/built-in-apps/
    it's listed here
    maybe it's in a folder?

  • Some one know, why my ipone 6, doesn't have 16GB? I only have 12.1

    why my ipone 6, doesn't have the 16GB that promissed on the publicity?

    That's 16GB before you take out the 3-4GB occupied by iOS and the bundled apps that come with it. Plus the 16GB quoted on the box is measured in decimal GB (10^9 or 1000000000bytes) whereas iOS reports the available/used storage in binary GB (2^30 or 1073741824bytes) instead.
    See How OS X and iOS report storage capacity - Apple Support for more information.

  • I have a doubt about The Single-Thread Rule

    The [url http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html#rule]Single Thread Rule states:
    Rule: Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread.
    I began to wonder about this because so much code seems to work just fine when it isn't executed in the event dispatching thread. Why are there exceptions? I went looking for some code which acted differently when executed on the event thread than when it was not. I found this
    http://forum.java.sun.com/thread.jsp?forum=57&thread=410423&message=1803725#1803725
    Now I started wondering why this was the case. What I found was that DefaultCaret adds a document listener to the document of the JTextComponent. In this listener, the insertUpdate() method specifically tests if it is running on the event dispatch thread and if it is, it updates the caret position.public void insertUpdate(DocumentEvent e) {
        if (async || SwingUtilities.isEventDispatchThread()) {
            // ... update the caret position ...
    }I then copied the code from DefaultCaret and made a MyCaret. I needed to tweek the code a little bit, but it ran. I removed the event thread test. It worked outside the event thread. There was a small difference in the results though. The textarea did not scroll all the way to the bottom. Almost, but not quite. I didn't test enough to make sure this was the only problem, but there was at least one problem.
    Now I started think about why this would be. The thought crossed my mind that the order of the events which were posted to the event queue were probably important. Sun found bugs when components were updated out of the event thread, so they essentially ignored events which weren't on the event thread and created the The Single-Thread Rule.
    A few days pass. I'm starting to wonder if Sun could have done a better job making Swing components thread safe. I also don't know that this specific case I found was the rule or the exception to the rule. But without insight into the design philosopy of Swing, I would have to examine all their components and see how they have written them and see if I can come up with a better design. That sound like a lot of work. Especially without getting paid for it.
    But wait a second, all you have to do is call the append() method of JTextArea on the event thread. If that is the case, why didn't they write the freakin component that way? Well, I'll try itclass MyTextArea extends JTextArea {
      public MyTextArea(int rows, int columns) { super(rows,columns); }
      public void append(final String text) {
        if (SwingUtilities.isEventDispatchThread()) super.append(text);
        else {
          SwingUtilities.invokeLater(new Runnable() {
            public void run() { myAppend(text); }
      private void myAppend(String text) { super.append(text); }
    }I change [url http://forum.java.sun.com/thread.jsp?forum=57&thread=410423&message=1803725#1803725]camickr's code to use a MyTextArea and it works fine without calling from the event thread. I've essentially moved The Single-Thread Rule to the component itself rather than relying on each and every one of the [url http://www.aboutlegacycoding.com/default.htm?AURL=%2FSurveys%2FSurvey6intro%2Easp]2.5 million Java programmers worldwide to use SwingUtilities.invaokeLater().
    Now for my question...
    Why didn't Sun do this?

    Swing is slow enough as it is. Lets not make it slower
    just
    because dense "programmers" don't know what they are
    doing.I agree with you in defending the current model, but aren't you a bit harsh there?!? ;-)
    Well, there are a number of not-so-dense programmers that expect such high-level components to be thread-safe. The question is worth asking whether Sun intentionally favor the explicit thread management for performance reasons, or whether this was an oversight.
    I'd go for the former (intentional) : indeed any GUI toolkit is inherently thread-based; there is always a distinction between the graphical thread(s) and the application threads - and the programmer always has to manage explicit thread creation to handle long-running event handlers without blocking the event dispatching thread. Extending thread concerns to the updating of components is therefore not a big move.
    So it seems fair that a core GUI toolkit does not hide thread issues (though to the best of my knowledge there is no such limitation in updating AWT components), or at least that's what Sun deemed.
    An ease-of-use-focused toolkit wrapping the core toolkit for thread-safety can be provided as a third-party product. Though I agree that wrapping the dozens of existing widgets and hundreds of methods is cumbersome - and the lack of such products probably shows it would have a low added value to trained developpers.
    Because your way is an extra method call and if
    statement, neither of which is necessary if you already know you
    are in the correct thread. Now count the number of methods
    which will need to be changed (and add up the extra cost).Indeed it's quite common to update several properties of several widgets in one bulk (when user clicks "OK", add a row to the table, change the title of the window, update status bar, re-enable all buttons, change some color,...).
    In this case explicit thread management doesn't spare one if but a dozen of redundant ifs!
    Note that there could have been if-less ways to cope for thread safety, such as creating a copy of the component's model when a change is made to a component, and switching the model only before paint() is called in the event-dispatching - of course coalescing all changes into the same "updated" model until paint() is called.
    But this would trade ease of use for redundant memory consumption, especially for some components with potentially huge models (JTree, JTable, JTextArea,...). And Swing appears to be already quite memory-greedy!

  • Get the current thread

    Hello,
    Thread suspension is an important operation for get the thread stack information�s (i.e. local variables...). JPDA provide three ways to suspend threads ThreadReference.suspend(),VirtualMachine.suspend(),or through events by setSuspendPolicy(int policy) method which suspend threads to the requested event occurs in the target VM.
    But, how can I know the current thread after Threads vm suspensions?
    By events we can deduce it, when MethodEntryEvent occur in the target vm through thread () method.
    But, what about the others tow Thread suspension methods?
    For example:
    //after suspension through vm.suspend().
    Virtual machine vm =�;
    List Threads = vm.allThreads();This list Returns a list of the currently running threads. But I don�t find any method to know which the current thread from this list is? �The index or the name of this current thread�.
    Later, what is the difference between ThreadReference.suspend (), VirtualMachine.suspend ().which one is preferable for suspend a running application, then extract the state of the current thread and save it in an object,for restoring its state later?
    please i need an answer,
    regards.

    You need a profiler. I can't recommend any, but do a google search.

  • Thread sends notify() before waiting thread says wait()

    In the code below the ref book I'm using "Sun certified Programmer for Java 2" had the calculator thread starting before the Reader thread was even created and hence the calculator thread was finished it's task and sending a notify() before the Reader even had it's socks on and saying wait()
    ( And this cost me a lot of time tryin to figure this problem out as the code must have being written for a Z80 processor and not a 2.4GHz P4)
    To fix this I put the calculator starting after the reader thread, but .......
    I would have thought that java would have some protection against this happening, ie, like a notify flag which a thread can set if it has done it's job BEFORE the waiting thread even starts waiting, ie a preemptive mechanism to help speed things up ?
    package MyPackage;
    public class Reader extends Thread {
    Calculator MyCalculator;
    public Reader(Calculator calc){
    MyCalculator = calc;
    public void run(){
    synchronized(MyCalculator){
    try{
    System.out.println("Waiting for calculation ... ");
    MyCalculator.wait();
    }catch (InterruptedException e){}
    System.out.println("Total is: " + MyCalculator.total);
    public static void main(String args []){
    Calculator calculator = new Calculator();
    //calculator.start();
    new Reader( calculator ).start();
    calculator.start();
    package MyPackage;
    public class Calculator extends Thread{
    int total;
    public void run(){
    synchronized(this) {
    for(int i=0; i<100; i++){
    total += i;
    System.out.println("Calculation complete, notifying waiting thread..");
    notify();

    It's up to the 'umble programmer to code it right. The code you quoted was crap.
    The most common way to wait is on a condition:
    while (hotAndBotherd())
        obj.wait();And then the notifying thread will take steps to change that:
    //code that cools off the hot and bothered
    obj.notify[all]();If the initial state of things is hot and bothered then there is no race condition: the first thread will wait.

  • Why notify() and notifyall() is in Object class

    pls help me
    why notify() and notifyall() methods which are related to thread are define in Object class,instead of defining in Thread class

    shouldn't be called on thread objects ever
    at all (one of my pet peeves with Java)Why not? It would make a nice entry in the IOJJJ (International
    Obfuscated Java Juggling Jamboree) if it existed ;-)First of all, sorry for my bad english. It's early here :)Nah, it's just a late a rainy Sunday afternoon here, so no problem ;-)
    Second of all, the way that Thread is implemented, at least on
    windows, it that calling Thread.join does a wait() on that thread object.
    Thus, if you call notify() on a thread, you could actually be waking up
    joined threads, which wouldn't be good. And if you called wait, you
    could get woken up if the thread finishes which violates the contract of
    wait and notify to some extent and also relies on an undocumented
    feature.I take back my previous remark: it could not just be a nice little entry in
    the IOJJJ, it would be a great entry in that contest! ;-)
    kind regards,
    Jos
    ps. your example is the first example that clearly gives a reason for
    spurious wakeups I've ever read; thanks; joined threads, I've got to
    remember that example. <scribble, scribble, scribble/> done. ;-)

  • Why can I no longer, after having downloaded Lion, write accents and other diacriticals when in the Google, Yahoo, FaceBook, or even here in this post? The new method for getting at the "option" symbols works fine in other places like spotlight, but now e

    Why can I no longer, after having downloaded Lion, write accents and other diacriticals when in the Google, Yahoo, FaceBook, or even here in this post? The new method for getting at the "option" symbols works fine in other places like spotlight, but now even the older "option+letter" doesn't work in most places.

    Chrome doesn't support the new accent/diacritics/macron chooser. I'm not sure about other browsers such as Firefox. You can use the old Option+letter combination that Doug suggested. Hopefully updates will solve these little incompatibilities shortly.
    Neill

  • Why Java Platarform Micro Edition 3.0 doesn't reflect the reality ?

    Hi guys,
    It's my first ME project and I would like to know why into version 3.0 of ME, don't have the necessity of create your access (read and write into files) methods using Threads, and in 2.5.2 I must have to use Threads ? Because my project runs smooth into 3.0 but not into my mobile (E63) and 2.5.2 emulator, after reading plenty docs, and change the emulator to 2.5.2 I did discover that have the need of using Threads. What is the right one and why the 3.0 doesn't reflect the reality ?
    There are any way that my project made with 3.0 runs smooth, how ?
    Thank you in advance.

    Hi once again,
    One example of what I'm doing, using the javax.microedition.io.file.FileConnection to save and read my files, though it only works into my 3.0 emulator.
    I'm using this method to open and read the file.
    private String loadCipher(String typedKey, String pathLoad, String fileName) throws DigestException {
            StringBuffer notFormattedText = new StringBuffer();
            pathLoad = pathLoad + fileName;
            FileConnection fc = null;
            InputStream is = null;
            try {
                fc = (FileConnection) Connector.open(pathLoad);
                is = fc.openInputStream();
                int ch = 0;
                for (int i = 0; i < fc.fileSize(); i++) {
                    if ((ch = is.read()) != -1) {
                        notFormattedText.append((char) ch);
                is.close();
                fc.close();
            } catch (IOException ioe) {
                System.out.print("Error reading!");  // Here I'll have to deal with exceptions
                System.out.print("IOException : " + ioe.getMessage());
            } catch (SecurityException se) {
                System.out.print("Error security!");  // Here I'll have to deal with exceptions
                System.out.print("Securuty exception : " + se.getMessage());
            pathLoad = FILE_ROOT;
            String myFileText = notFormattedText.toString();
            byte[] keyFromFile = readKey(typedKey, myFileText.getBytes()); // Here is where the program goes and decript my file
            return new String(keyFromFile);  // Here I return the decripted text to be compared with password or for that the user might read it.
        }I don't intend to use Thread to run it, although I'm afraid of that it's the only way and with this all program structure will have to be re-designed.
    Anyone knows if Thread is needed just to use the javax.crypto.... and javax.security..... ? Because I'm lost.
    Thank you in advanced

  • Why can't I post my resume from Pages to the web or an email on my iPad?? I've tried using iCab, downloading google docs, etc. I understand it's not possible from iPad but why???

    Why can't I post my resume from Pages to the web or an email on my iPad?? I've tried using iCab, downloading google docs, etc. I understand it's not possible from iPad but why??? If I can't use safari to do it is there any other way?? Seriously, are iPads only used for watching Hulu, playing games, fb and twitter? My phone can do that!! Worst $500 I ever spent.

    We don't want to email it.....  we want to upload it.
    Then why did you say (emphasis added):
    Why can't I post my resume from Pages to the web or an email on my iPad??
    There are plenty of methods for putting a resume online, where a potential employer can download it, though admittedly the iPad is less flexible in this regard than a computer.  Nobody ever has claimed otherwise.  However, I get the feeling you're not actually looking for an answer to anything, and you're just posting to complain.  Note that that is a violation of the Apple Support Communities Terms of Use, which you agreed to when signing up for an account here.
    I wish I had gotten a Galaxy Tab.
    Then sell your iPad and go buy one.  You will have no problems whatsoever finding a buyer.

  • I cannot figure out how to make the text larger on an incoming email.  The finger method doesn't work and I cannot find any toolbar with which to do it.  I could find nothing in settings also.  Plese help and thank you.

    I cannot figure out how to make the text larger in a received email.  The finger method doesn't work and I can find no tool bar as I can for composing emails.  I can find nothing in settings.  Please help and thank you in advance.

    Hi there,
    Download a piece of software called TinkerTool - that might just solve your problem. I have used it myself to change the system fonts on my iMac. It is software and not an app.
    Good wishes,
    John.

Maybe you are looking for

  • Can I install Phone designer for all user?

    Hi I have phone designer application I install it on my PC but when I install it for anther user and give me error Unable to connected to server. Is there any parameters needs to check on CUCM? How many times can I install it? Thanks Kaff

  • How do you increase the Brush Size past 50 on the Stroke Effect?

    Hey Everyone, I created a photo in Photoshop and I imported it to AE, and I've been trying to create a Spray Paint effect by using the Stroke effect and Reveal Original Image to look look like as if I'm spray painting the the picture on the wall. All

  • Diff between EDI and ALE

    Cand any one of you tell me exact difference between EDI and ALE

  • Webservices in Abap

    Hi All, Please can anyone provide with a samplecode in ABAP on how to  call a Webservice . It's urgent. Thanks and regards, Uma.

  • Business Partner in SAP EHS

    Dear Friends How to create Business Partner (Health Centre, Physician, Authority, Laboratory etc) in SAP EHS. Is it created in SAP EHS or is it created in MM as a vendor/service provider. Please let me know the process of creating business partner fo