"Filthyrichclients" Reading notes (i)-swingのedt

Source: Internet
Author: User
Tags thread

"Filthyrichclients" read the first few chapters, now my experience in conjunction with the work of swing desktop development experience, on this book some important concepts of an analysis of some of the book's omissions and vague place in time to supplement, while making the reader to eliminate the long-standing " Swing Low performance, ugly interface "and so on old ideas. Reading notes only talk about my understanding of swing, will inevitably make mistakes, but also hope that the broad masses of readers advice.

The second chapter of the book is a systematic introduction to swing's threads in the-swing rendering principle. It's been very in-depth compared to other swing tutorials of the same kind. But if the reader has a limited grasp of threads before, especially the coder who write code more casually, write code that is similar to the following:

jButton1.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e) {
   // TODO
  }
  });

Such a code might be a "masterpiece" generated by a tool like NetBeans. But if this person is any more lazy, it may write a long stack of code directly under the TODO, along with unpredictable I/O operations, and many people accuse the interface of being stuck in a swing performance problem. In the new JDK, swing has improved a lot in terms of performance, so to speak: the time spent on the interface is negligible compared to the application's own business calculations. But if these abuses do not change, swing will never be "fast", SWT also, because they are single-threaded graphics toolkit.

The book says: "The eventqueue distribution mechanism is managed by a single thread called the event-distributing thread (EDT)." Like many other desktop APIs, swing executes GUI requests into an event queue. If you don't understand what event queues, EDT, and how they work, you first have to clarify four important concepts: synchronous and asynchronous, serial and parallel, producer consumer mode, event queue. (different domain serial and parallel meanings may be different)

Synchronous vs. Asynchronous: Synchronization is when a program starts processing an event and waits for a processing result, or waits for a request to execute after the request is initiated, before which the program is blocked until the request completes. Asynchronous is returned immediately after the current program initiates a request, the current program does not immediately handle the event and waits for the result of processing, and the request is processed at a later time.

Serial and parallel: the so-called serial is to handle the request sequence execution, processing one to process the next, parallel can be understood as concurrency, is to handle multiple requests at the same time (in fact, we can only understand that, especially the number of CPUs less than the number of machines, the real meaning of concurrency is not there, Each thread is executed alternately and intermittently. The following figure illustrates the serial and parallel mechanisms. It can be said that, before the introduction of multithreading, for the same process or program is to perform a serial operation.

Serial: 

Parallel:

Producer/Consumer Model: Imagine a scenario in which a conveyor belt in a workshop has one or more entrances that continuously produce the goods to be processed, which is called the producer; the end of the conveyor belt is one or more workers working on the goods, called consumers. Sometimes, because there is not enough cargo on the conveyor belt to make a worker temporarily idle, and sometimes because some of the goods need to be processed for longer period of time on the conveyor belt backlog of goods to be processed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.