Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6980209

Make tracking SecondaryLoop.enter/exit methods easier

    Details

    • Subcomponent:
    • Resolved In Build:
      b68
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Here is a code snippet from java.awt.SecondaryLoop JavaDoc:

           SecondaryLoop loop;

           JButton jButton = new JButton("Button");
           jButton.addActionListener(new ActionListener() {
               {@code @Override}
               public void actionPerformed(ActionEvent e) {
                   Toolkit tk = Toolkit.getDefaultToolkit();
                   EventQueue eq = tk.getSystemEventQueue();
                   loop = eq.createSecondaryLoop();

                   // Spawn a new thread to do the work
                   Thread worker = new WorkerThread();
        * worker.start();

                   // Enter the loop to block the current event
                   // handler, but leave UI responsive
        ** if (!loop.enter()) {
                       // Report an error
                   }
               }
           });

           class WorkerThread extends Thread {
               {@code @Override}
               public void run() {
                   // Perform calculations
                   doSomethingUseful();

                   // Exit the loop
        *** loop.exit();
               }
           }

        The code marked with (*) spawns a new thread. Note that (***), which is called on this new thread, can potentially be invoked before the loop is started with (**). This is not a problem in java.awt.Secondary loop, however there's no easy way for developers to detect and resolve this situation.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  ssadetsky Semyon Sadetsky
                  Reporter:
                  art Artem Ananiev (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: