Blocking the UI Thread

Hi all

I wrote a utility class to make sure that at some point there is at most a dialog box showed and avoid duplication (this can occur because the application is made of many threads and each one can need alert the user).

This is the code:

public class UserDialogUtils extends Thread implements SystemListener2 {

    private boolean isForeground = false, isBacklightOn = false;
    private final Object screenLock = new Object();

    private boolean newDialogRequestPresent = false, lastDialogClosed = true,
            lastDialogResultConsumed = true;

    private static UserDialogUtils instance = null;

    private UserDialog currentDialog = null;

    private UserDialogUtils() {
        super();
        isBacklightOn = Backlight.isEnabled();
        isForeground = Application.getApplication().isForeground();
    }

    public static synchronized UserDialogUtils getInstance() {
        if (instance == null || !instance.isAlive()) {
            if (instance != null) {
                Application.getApplication().removeSystemListener(instance);
            }
            instance = new UserDialogUtils();
            Application.getApplication().addSystemListener(instance);
            instance.start();
        }
        return instance;
    }

    public synchronized void popupAlert(String msg) {
        while (!(!newDialogRequestPresent && lastDialogClosed && lastDialogResultConsumed)) {
            try {
                wait();
            } catch (InterruptedException e) {
            }
        }
        currentDialog = new UserDialog(UserDialog.DIALOG_ALERT, msg, 0);
        newDialogRequestPresent = true;
        lastDialogResultConsumed = false;
        notifyAll();

        while (!(!newDialogRequestPresent && lastDialogClosed))
            try {
                wait();
            } catch (InterruptedException e) {
            }
        // int res = currentDialog.res;
        lastDialogResultConsumed = true;
        notifyAll();
        return;
    }

    public synchronized boolean popupYesNo(String msg) {
        while (!(!newDialogRequestPresent && lastDialogClosed && lastDialogResultConsumed)) {
            try {
                wait();
            } catch (InterruptedException e) {
            }
        }
        currentDialog = new UserDialog(UserDialog.DIALOG_YES_NO, msg, 0);
        newDialogRequestPresent = true;
        lastDialogResultConsumed = false;
        notifyAll();

        while (!(!newDialogRequestPresent && lastDialogClosed))
            try {
                wait();
            } catch (InterruptedException e) {
            }
        int res = currentDialog.res;
        lastDialogResultConsumed = true;
        notifyAll();
        return res == Dialog.YES;
    }
            // Implements method from SystemListener2
    public void backlightStateChange(boolean on) {
        synchronized (screenLock) {
            isBacklightOn = on;
            screenLock.notifyAll();
        }
    }
        // Called by main UIapp when switching fgd/bkgd
    public void setForeground(boolean isForeground) {
        synchronized (screenLock) {
            this.isForeground = isForeground;
            screenLock.notifyAll();
        }
    }

    public void run() {
        while (true) {
            synchronized (instance) {
                while (!(newDialogRequestPresent && lastDialogClosed)) {
                    try {
                        wait();
                    } catch (InterruptedException e) {
                    }
                }

                newDialogRequestPresent = false;
                lastDialogClosed = false;
                currentDialog.manage();

                notifyAll();
            }
        }
    }

    public synchronized void dialogClosed(UserDialog closedDialog) {
        if (closedDialog == currentDialog) {
            lastDialogClosed = true;
            notifyAll();
        } else {
            // shouldn't ever happen
        }
    }

    private class UserDialog {
        public static final int DIALOG_STATUS_SHOW = 1;
        public static final int DIALOG_INFORM = 2;
        public static final int DIALOG_ALERT = 3;
        public static final int DIALOG_YES_NO = 4;
        public static final int DIALOG_OK_CANCEL = 5;

        private int type = 0;
        private String msg = null;
        private int millis = 0;

        private int res = 0;

        public UserDialog(int type, String msg, int millis) {
            super();
            this.type = type;
            this.msg = msg;
            this.millis = millis;
        }

        public void manage() {
            synchronized (screenLock) {
                while (!(isBacklightOn && isForeground)) {
                    try {
                        screenLock.wait();
                    } catch (InterruptedException e) {
                    }
                }

                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        switch (type) {
                        case DIALOG_STATUS_SHOW:
                            if (millis > 0)
                                Status.show(msg, millis);
                            else
                                Status.show(msg);
                            break;
                        case DIALOG_INFORM:
                            Dialog.inform(msg);
                            break;
                        case DIALOG_ALERT:
                            Dialog.alert(msg);
                            break;
                        case DIALOG_YES_NO:
                            res = Dialog.ask(Dialog.D_YES_NO, msg);
                            break;
                        case DIALOG_OK_CANCEL:
                            res = Dialog.ask(Dialog.D_OK_CANCEL, msg);
                            break;
                        default:
                            break;
                        }
                        dialogClosed(UserDialog.this);
                    }
                });

            }
        }

    }

}

I can't understand how and why, but sometimes it can cause a blockage (I believe that the lock of the event).

Essentially, in some cases, UIApplication will never call the executable content in the UserDialog instance manage() method.

This means that, when it happens, the screen freezes as if it were before a popup methods (UserDialogUtils.getInstance () .popupAlert ("Please do not freeze")) was called.

What Miss me?

Thank you

Luca

I appreciated that the question you were worried but not specifically related to the UserDialogUtils code, but I thought there is no point in studying something depends on the UserDialogUtils until UserDialogUtils is processing properly.

I could be missing something, but isn't sync it on methods prevents actually several Threads displaying dialog boxes at the same time?

You only need the loop because manage() returns before the dialog box was dismissed.  And this happens because you use invokeLater and not invokeAndWait.  Your dialogs block the Thread event at some point, I'm not sure that your workaround (loop) here is really necessary.

But to be honest, I haven't looked hard in the code.

In any case, I have the answer to your problem I think.

fieldChanged() is called on the event Thread.  If you hold the event walking till it ends.  Now in your treatment, that you never come back of popupAlert until something got the wire of the event, specifically the dialog box.  If you are in a bind.

Short answer, do not call the methods in UserDialogUtils while holding the thread of events.

Tags: BlackBerry Developers

Similar Questions

  • How to avoid the LrStringUtils.encodeBase64 and LrFileUtils.readFile to block the main thread?

    Hello

    During the publication of the photos, I use LrFileUtils.readFile to read the exported file and LrStringUtils.encodeBase64 on the result of it. These two functions are the only ones in my process which seems to block the main thread of LR.

    I tried to put these two functions in an asynchronous task using LrTasks.startAsyncTask () and LrTasks.yield () to wait for the task at hand, but LR UI is still freezing for 1 or 2 seconds when I execute these functions.

    Is this normal? I'm doing it wrong? Is there a way I can avoid this?

    Thank you very much!

    Perhaps you need to read the file and encode it into smaller pieces (for example 100K bytes at a time), the use of Lua file: read() rather than LrFileUtils.readFile ().

  • How can I do to block the main thread when to display a dialog box

    I have a problem to block the user interface main thread when to display a dialog box (the dialog was created by the main Application), and when the dialog box is closed, the main Application can go to the next step.
    Here is my code:

    SerializableAttribute public class TitledPaneExample extends Application {}
    instance of TitledPaneExample private;
    StackPane mainModalDimmer;

    /*
    * (non-Javadoc)
    *
    * @see javafx.application.Application #start (javafx.stage.Stage)
    */
    @Override
    public void start (point primaryStage) bird Exception {}
    instance = this;
    primaryStage.setTitle (this.getClass () m:System.NET.SocketAddress.ToString ());

    final StackPane layerPane = new StackPane();
    layerPane.setDepthTest (DepthTest.DISABLE);
    layerPane.setStyle ("background - fx - color: BLACK ;"); ")

    Vb VBox = new VBox();
    vb.setStyle ("background - fx - color: BLUE ;"); ")
    vb.getChildren () .add new (Label ("1"));
    vb.getChildren () .add (Label ("2")) new;
    vb.getChildren () .add new (Label ("3"));
    vb.getChildren () .add (Label ("4")) new;

    Bt1 button = new Button ("bt1");
    BT1.setOnAction (new EventHandler < ActionEvent > () {}
    {} public void handle (ActionEvent event)
    System.out.println ("bt1 trying to the new dialog box > > >");
    Dialogue di = new dialog box (instance, "some trick here!");
    System.out.println ("bt1 dialogue again successfully, try to show");
    di. Show();
    System.out.println ("bt1 dialog hide? < < < < ");"
    }
    });
    vb.getChildren () .add (bt1).

    layerPane.getChildren () .add (vb);

    mainModalDimmer = new StackPane();
    mainModalDimmer.setId ("MainModalDimmer");
    mainModalDimmer.setMaxSize (Double.MAX_VALUE, Double.MAX_VALUE);
    mainModalDimmer.setVisible (false);
    mainModalDimmer.setStyle ("background - fx - color: RED ;"); ")
    layerPane.getChildren () .add (mainModalDimmer);

    Scene sc = new scene (layerPane, 800, 600);
    primaryStage.setResizable (true);
    primaryStage.setScene (sc);
    primaryStage.show ();

    }

    /**
    * Display the node given as a floating dialog on the entire application, with
    * the rest of the application grayed out and blocked from mouse events.
    *
    @param message
    */
    {} public void showModalMessage (message from node)
    mainModalDimmer.getChildren () .add (message);
    mainModalDimmer.setOpacity (0);
    mainModalDimmer.setVisible (true);
    mainModalDimmer.setCache (true);
    TimelineBuilder
    . Create()
    () .keyFrames
    new KeyFrame (Duration.seconds (1),)
    new EventHandler < ActionEvent > () {}
    {} public void handle (ActionEvent t)
    mainModalDimmer.setCache (false);
    }
    }, new KeyValue (mainModalDimmer
    . opacityProperty(), 1.
    Interpolator.EASE_BOTH))) infrastructure)
    . Play();
    }

    /**
    Hide the any modal message that appears
    */
    public void hideModalMessage() {}
    mainModalDimmer.setCache (true);
    TimelineBuilder
    . Create()
    () .keyFrames
    new KeyFrame (Duration.seconds (1),)
    new EventHandler < ActionEvent > () {}
    {} public void handle (ActionEvent t)
    mainModalDimmer.setCache (false);
    mainModalDimmer.setVisible (false);
    mainModalDimmer.getChildren () .clear ();
    }
    }, new KeyValue (mainModalDimmer
    . opacityProperty(), 0,.
    Interpolator.EASE_BOTH))) infrastructure)
    . Play();
    }

    /**
    @param args
    */
    Public Shared Sub main (String [] args) {}
    Launch();
    }

    Dialogue/public class extends TitledPane {}
    private owner of TitledPaneExample = null;
    instance of TitledPane private;

    Dialogue (owner of TitledPaneExample, String message) {}
    This.Owner = owner;
    this.parentThreand = Thread.currentThread ();
    This.instance = this;
    this.setExpanded (true);
    this.setText ("Dialog");
    this.setMaxWidth (400);
    this.setPrefWidth (300);
    this.setMinWidth (200);

    Label the tx = new Label ("message");
    tx.setTooltip (new Tooltip (message));
    tx.setWrapText (true);
    tx.setContentDisplay (ContentDisplay.LEFT);

    Bt button = new Button ("OK");
    bt.setOnAction (new EventHandler < ActionEvent > () {}
    {} public void handle (ActionEvent event)
    masquer();
    }
    });

    Sp ScrollPane = new ScrollPane();
    sp.setHbarPolicy (ScrollBarPolicy.AS_NEEDED);
    sp.setVbarPolicy (ScrollBarPolicy.AS_NEEDED);
    sp.setContent (tx);

    Hb HBox = new HBox (30);
    hb.setPrefHeight (40);
    hb.setAlignment (Pos.CENTER_RIGHT);
    hb.getChildren () .add (bt);

    BP BorderPane = new BorderPane();
    bp.setCenter (sp);
    bp.setBottom (hb);

    this.setContent (bp);
    }

    {} public void show()
    System.out.println ("dialogue show() 1 > > >");

    owner.showModalMessage (instance);

    System.out.println ("dialogue show() 2 > > >");

    }

    public void masquer() {}
    System.out.println ("dialogue masquer() 1 > > >");
    this.owner.hideModalMessage ();

    System.out.println ("dialogue masquer() 2 > > >");
    }
    }

    }

    I'm also interested in how to do this without the use of a step.

    But, if you are ready to use a step for this, you can create a useful first step (without borders) with its owner being your current stage. Then, you can call the function showAndWait on stage that allows to block the thread of your application. For example, I implemented a DialogStage like this:

    package hs.mediasystem.util;
    
    import javafx.animation.KeyFrame;
    import javafx.animation.KeyValue;
    import javafx.animation.Timeline;
    import javafx.event.EventHandler;
    import javafx.scene.effect.ColorAdjust;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    import javafx.stage.Window;
    import javafx.stage.WindowEvent;
    import javafx.util.Duration;
    
    public class DialogStage extends Stage implements Dialog {
    
      public DialogStage() {
        super(StageStyle.TRANSPARENT);
    
        this.setTitle("MediaSystem-dialog");
    
        initModality(Modality.APPLICATION_MODAL);
      }
    
      protected void setParentEffect(Stage parent) {
        ColorAdjust colorAdjust = new ColorAdjust();
    
        Timeline fadeOut = new Timeline(
          new KeyFrame(Duration.ZERO,
            new KeyValue(colorAdjust.brightnessProperty(), 0)
          ),
          new KeyFrame(Duration.seconds(1),
            new KeyValue(colorAdjust.brightnessProperty(), -0.5)
          )
        );
    
        parent.getScene().getRoot().setEffect(colorAdjust);
    
        fadeOut.play();
      }
    
      protected void removeParentEffect(Stage parent) {
        parent.getScene().getRoot().setEffect(null);
      }
    
      protected void recenter() {
        Window parent = getOwner();
    
        sizeToScene();
    
        setX(parent.getX() + parent.getWidth() / 2 - DialogStage.this.getWidth() / 2);
        setY(parent.getY() + parent.getHeight() / 2 - DialogStage.this.getHeight() / 2);
      }
    
      @Override
      public final void showDialog(final Stage parent, boolean synchronous) {
        initOwner(parent);
    
        setParentEffect(parent);
    
        setOnShown(new EventHandler() {
          @Override
          public void handle(WindowEvent event) {
            recenter();
            onShow();
          }
        });
    
        if(synchronous) {
          showAndWait();
        }
        else {
          show();
        }
      }
    
      protected void onShow() {
      }
    
      @Override
      public void close() {
        removeParentEffect((Stage)getOwner());
        super.close();
      }
    }
    
  • I have Ad Block, but a site keeps popping up. 'S called it focusAd. When I go to the block, he wants to block the site I'm. How can I get rid of him?

    I do surveys. When I go to the survey site, focusAd appears on the page and I have to type "Continue" to move forward. When I try to block focusAds, he wants to block the site survey, not focusAds. I even if I "chose" to it, apparently not. Thanks, Judy

    Ads can be inserted by bad Add-ons. Because these are often installed outdoors for Firefox, I suggest starting here:

    Open the Control Panel, uninstall a program. Click on the column heading "installed on" to group infections, I mean additions by date. This can help the undisclosed items bundle smoker who snuck out with some software, you have agreed to install. Out as much garbage as possible here.

    Then, in Firefox, open the page modules using either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click Extensions. Then, in case of doubt, disable (or delete, if possible) not recognized and unwanted extensions.

    Often, a link will appear above at least an extension disabled to restart Firefox. You can complete your work on the tab and click one of the links in the last step.

    Finally, you can "absorb" remain problems with the scanning/cleaning tools mentioned earlier in this thread.

  • Satellite Pro L500 - press Fn key blocks the laptop computer to blue screen

    Hi all
    First post so please ask if I did not include all the necessary information.

    I have the Satellite Pro L500-1TX (Win 7 32 bit os) and everything worked fine including the Fn menu drop-down button.

    Now, whenever I press the Fn key, it blocks the laptop to a blue screen. The computer then restarts automatically and that it was an unplanned shutdown offers the usual safe mode option.

    Unfortunately, I do not know when this started as I do not use the fn often hesitate so just do a system restore. I don't know how far back to go. It was several weeks before I associated accidents hit the Fn key.

    Any suggestions as to which Toshiba drivers may need to be reinstalled. The computer otherwise works fine.

    Cheers in advance
    MTV

    Great! Thanks for this feedback that I also found other threads about Support Flash Card utility and it is the tool command keys FN so read the forum in other threads contributes without doubt! ;)

  • Blocks the execution of the user Image Acquisition interface

    I am currently trying to create a user interface that displays images from a camera attached to a microscope with a mobile table.  The user is able to interact with the images and can click on them, which causes the table to move to a new location.  Acquisition is made by calling a DLL, the DLL grey flycapture point camera, using a call library function node.

    When I acquire images at 15 frames per second, it has no problem with user input.  However, when I drop the acquisition at 2 frames / second (necessary if you need to have the exposure time), labview seems to take a break from the user interface while the image acquisition is underway.  Interaction of the UI seems possible in the holes between the image acquisitions.

    I'm sure that this is happening because there is a kind of blocking going on here.  The program is waiting for the new image to be returned and will not not something else happen while he waits.  I have image acquisition running in a separate, called function from a higher level, VI, which puts the image data in a global variable (I know I know... global variables).  When I need to display the image, I read of the global variable and display it on my form of user interface.

    I think I need to run things in separate threads to avoid the problems that I have because I have a dependency that is the cause of blocking.  I'm looking for any suggestions on how I can the architect this.  I have thought about using a VI server to launch the acquisition of the camera and will try to implement this, but I wonder if there is another method that I'm missing here.

    Any suggestions would be greatly appreciated!  I use LabVIEW 8.6 on a Windows 7 machine indeed.  I do not use LabVIEW image acquisition module.

    Thank you

    Hey Gerry,.

    It's Paul in Ministry here at National Instruments engineering applications. What Paul was referring to a call library function node configuration properties. If you right-click on the node library function call you can click on configure and you should see a window that looks like the image below.

    As you can see, you have the option to select run this library in the UI thread or any thread. This is important because there is only a single user interface thread. Therefore, deadlocks can occur when the code is written in parallel, but operations are both occurring in the UI thread. What results is a part of the code has to wait that the other part at the end and so the lock upwards in the user interface. The reason why the call library function node is set to run in the default UI thread is now, because only the security thread functions can be performed in any thread. So before you change this configuration it is strongly recommended that you check that the functions you call are thread-safe. You can also check which configuration, the node library function call is in the color of the node itself. If it is an orange color which means that it is set to run in the UI thread. If it is a pale yellow color, it is set to run in any thread. Let me know if you have any other questions!

    Paul M

  • The control law of read/write FPGA on the loop of the root / the UI thread?

    Hi all

    As the title suggests, the read/write control FPGA, https://zone.ni.com/reference/en-XX/help/371599H-01/lvfpgahost/readwrite_control/, is on the loop of the root / the UI thread?

    Watch, https://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/multitasking_in_labview/, this would indicate as that, but I would get a good response.

    Kind regards

    David

    While I'm not 100% if it acts on the loop of the root / UI thread - calls to the FPGA (e.g. control of read/write operations FIFO) block permanently. I remember having a weird problem in the past where my FPGA operations have been suspended because I was expecting given FIFO elsewhere.

    You should be able to test this easily enough - try to open a file dialog during playback of your FPGA. If playback crashes while the dialog is open, you have a loop of root problem.

  • can someone tell me how to run my iTunes after a deaf mute DEP (Data Execution Prevention) installed in my computer? Seriously, he's blocking the iTunes... for the love of God!

    can someone tell me how to run my iTunes after a deaf mute DEP (Data Execution Prevention) installed in my computer? Seriously, he's blocking the iTunes... for the love of God!

    Hi JulietZhang,
     
    -What version of the operating system are you using?
    -Have you been able to use Itunes without any problems before?
     
    Try these methods in order:
     
    Method 1: Try to add the program to the list Data Execution Prevention (DEP) and check if it helps.
    Refer to this link for steps to do the same, if you are using Windows XP:
     
    Refer to this link for steps to do the same, if you are using Windows Vista:
     
    Method 2: This issue may be caused by third-party codecs installed on your system.

    Look at Apple's site for assistance. http://discussions.Apple.com/thread.jspa?threadID=1908393

    He will explain how to uninstall Quicktime from your computer and re - simply install the program itself.

  • How to pause the timer thread...

    Hello

    I want to make a break the "timer" thread... or I can tell want to set mode 'waiting' and then notify when something is filled.

    _CatchTimer timer = new Timer();
    CatchAppNameTimer _catchTimerTask = new CatchAppNameTimer (_catchTimer);
    _catchTimer.schedule (_catchTimerTask, 0, 5000);

    My "TimerTask (_catchTimerTask)" whenever displays a Popup...

    This popup form has two buttons - unlock, undo.

    Basically I want that, until the user clicks on... a the unlock / cancel btn, thread prepares time on standby... when the user click on open it / cancel... only after then time button thread gets notify.

    I am currently using a Boolean variable in the run method of "timertask"... to handle the deadlock situation... it's TimerTask called in every few seconds... even when the popup screen showed...

    As follows:

    public void run()
    {
    GlobalSingleton obj = null;
    obj = GlobalSingleton.getInstance ();
            
    If (obj.getShowDialog ())
    return;
           
    unlockField();
    }

    When the first "unlockFiled()" called... I put a Boolean variable as true (using Runtime store)... whose value is extracted by the getShowDialog() method.  and in

    fieldChanged (field field, int context) {} method of two Unlock / Cancel button... I put Boolean value of var as wrong... by calling...

    GlobalSingleton obj = null;
    obj = GlobalSingleton.getInstance ();
    obj.setShowDialog (false);

    But the right approach is "timer task" should not be repeated... until the user either unlock / cancel button and the control becomes out of {} fieldChanged (field field, int context) method.

    should I use a differnet thread to manage the... wait - notify operations on the Timer object... based on a Boolean variable.  I hv already tried this approach... but impossible to get a solution...

    I will be gratefull for your suggestions...

    Kind regards.

    I wouldn't use a timer for this job, I would use a Thread running continuously.  The wire would be just "sleep" for a second, then check.

    In regards to your screen, you have two choices.

    (1) the easiest is simply put your app in the foreground.  This means that you can actually leave the currently running Thread.  Because if your application is in the foreground, it will not try to block.

    With this approach, the screen that you view will be a simple screen and you can code like that.

    When the user enters the PIN code, you can make the activity on the native application.

    (2) the other option is to use a Global context screen.  It's possible but more complicated to code and I see no benefit to this approach (1), except that he's looking for a little more "pleasant".  But I don't think that "kindness" is important to you.

    As indicated on the other thread, I don't know how to close the native application.  But who needs to be discussed on the other Thread.  Have this concentration of Thread on sort how to get your screen to superimpose the native application after checking every second.  The approach I have to do it and a lot easier than trying to use a timer task.

  • How to get the worker thread to wait for a course of UI thread ends

    I managed so far to have a thread so far work send a signal to a class in the UI thread, view a map, capture the data in this worksheet and send a signal to slot in worker thread.

    To test that the steps in the UI could do I just put the worker thread in a loop with a sleep and a counter.

    What I don't know is how interrupt the loop when the final signal is sent. I know that the signal is received but the crack does not control until that the loop ends while I want the slot for the control reception and tell the loop at the end.

    I read the documentation in BlackBBerry and Qt on the threads, mutexes, condvars, QWaitCondition etc., but none of them quite make sense to me in this situation and I can't determine which would be the best or the only one to use here.

    Anyone could do his script to work for them?

    Does not appear that the use of mutexes, condvars, are applicable to this situation, as I have only main and a worker thread to synchronize. Signal wire loop blocks so slot does not control until the loop ends. This makes sense because a thread can have only a single process point of execution. Maybe with another thread, it might work but cannot solve the logic.

    However, to find a simple solution using a thread with a loop containing beds and overall, set variables to date by the UI thread that the loop check and then fall back to sleep or ends. I don't allow so many people then, if the loop has not yet finished I invited user "More time to enter the data do you need?" and set end or loop.

  • Update of the screen, threading and synchronization

    I have a game I developed that uses multiple threads to process. The game does not focus on the user by itself and seems to be accelerating when there are more items on the screen and slows down when there is less. I have four threads in use. Three of them are used to update the main (UI) thread and run continuously; two update a class watch stop custom, and the third simply disabled the screen to force a refresh. All three of the threads use locks objects synchronized; That's why I think it slows down when nothing is on the screen, because they constantly block. I do not have variables that are constantly updated by the thread and read survival gear each iteration; which I was I use locks. I use the IDE 4.7 and the simulator of the storm. Profiling code over a minute 3 period shows that almost 60% of the execution time is during one of the locked rows (block I'm of course). I was wondering what I should use locks because only the UI thread updates one of the three? If so, is there a better way. Code can be provided if necessary.

    BUDOKAI-is that they have a book of text on the famine of lock?

    http://Java.Sun.com/docs/books/tutorial/essential/concurrency/starvelive.html

    [ed, I would also like to make out this seems to be a tight loop so that it also uses time spinning CPU]

    during the liberation that briefly up to 2 locks]

    While (true) {}
    synchronized (runLock) {}
    If {(race)
    synchronized (pauseLock) {}

  • JTextField.setText blocks Java in thread EDT

    Hello

    When I try to setText in a particular context, the application blockes (hangs forever).

    I've used EDT thread like this:

              if(!javax.swing.SwingUtilities.isEventDispatchThread())  {
                    System.err.println("NOT EDT THREAD");
                    Runnable doThread = new Runnable() {
                        @Override
                        public void run() {
                              temp.setText(VAL);
                        }
                    };          
                    SwingUtilities.invokeLater(doThread);
                } else {
                    System.err.println("IS EDT THREAD");
                    temp.setText(VAL);
                    System.err.println("AFTER IS EDT THREAD");
                }
    
    
    

    So my request prints "IS the EDT THREAD" but does not print 'AFTER IS EDT THREAD".

    The frame is like this:

    1. a new thread is started from EDT

    2. this new thread creates a new JPanel with a few swings and sets values in these swings

    3. some of these fluctuations were associated events DocumentListener and they begin to run the text for some JTextFields setting

    The hanging appears when these events are executed.

    These events are not started from EDT, but they are considered by Java as EDT. Is this ok?

    Is there something I can do to fix this?

    Thank you.

    Wrong with setText in EDT? I've probably missed something essential.

    Yes - it is wrong to do almost anything on the EDT.

    The EDT has ONE PURPOSE and one purpose: "ship events". It's the "crier" that allows others to know when important things happen.

    A factor must deliver MAIL on their road. You want the factor to stop and chat with all the way from your neighbor? Or even stop in a cup of tea? What is the delay in the delivery of the mail.

    Can you please explain how should I setText when in EDT?
    

    Of course - don't DO THIS!

    You already know what is happening. Any code that you run in the SOW must be as fast and as short as possible.

    You have been informed of an event. So make a note of the details or notify other processes (for example to add a message to a queue) and out of this EDT as fast and clean as possible.

    See the Java tutorials

    https://docs.Oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html

    Tasks on the event dispatch thread must end quickly; If they are not, of events does not support save and user interface stops responding.

    See this last clause? 'save events? does not? Sound familiar.

    When you call Java code as "setText" you call Java code and you have NO CONTROL over what does this code or how it does it.

  • messages between the main thread and the FX application thread

    I run a thread of the Application of FX for a main thread using Application.launch [described here: {: identifier of the thread = 2530636}]

    I try to have the application thread return information on the main thread, but Application.launch returns void. Is there an easy way to communicate between the main thread and the thread of the Application?

    So far, I googled and found:
    -MOM (Message Oriented Middleware)
    -Sockets

    Thoughts/ideas/examples are appreciated--especially examples ;)--now I try to use Sockets to show/hide the application and data transmission.

    What is the preferred method? Are there others that I did not find (gasp) via Google?

    Dave.

    Published by: cr0ck3t on April 30, 2013 21:04

    Published by: cr0ck3t on April 30, 2013 21:05

    Is there an easy way to get a reference to these objects to both the main thread and the thread of Application FX - called via Application.launch () since the main thread? Or what I need to use Sockets or MOM?

    Not much to do with the concurrent programming is what I would call easy. It looks easy - but it's not.
    You can do kind of what you're describing using Java concurrency constructs without using sockets or a package of Message Oriented Middleware (MOM).
    With the Java concurrency stuff you really implement your own form or MOM light.
    If you have quite an application is complex with many messages of comes and goes, then a sort of package for MOM such as the camel and ActiveMQ (http://camel.apache.org) is useful.
    ---------
    You can find a sample of the various interactions of thread with JavaFX here:
    https://gist.github.com/jewelsea/5500981 "Simulation of dwarf dragons using multiple threads to eat."
    Related code is just demo-ware to try different competitive access facilities and not necessarily a recommended strategy.
    If your curiosity, you can take a look and try to work out what it is, what it does and how it does.
    The main reason followed is that of a blocking queue:
    http://docs.Oracle.com/javase/6/docs/API/Java/util/concurrent/BlockingQueue.html
    ---------
    Note that once you call launch of the main thread, no subsequent statement in the main method will be different until the JavaFX application terminates. If you can't start from the main thread and communicate with the main thread JavaFX application. Instead, you need to spawn another thread (or a set of threads) for communication with the JavaFX application.
    ---------
    But really, in most cases, the best solution with the simultaneity is not care at all (or at least as little as possible). Write everything in JavaFX, use the animation of JavaFX framework to time related things and the simultaneity of JavaFX utilities for when you really need multiple interaction of wire.
    http://docs.Oracle.com/JavaFX/2/threads/jfxpub-threads.htm
    ----------
    For additional assistance, you may be better off describing exactly (i.e. really specific) what you're trying to make in a new question, perhaps with a solution of the sample in a http://sscce.org NBS

  • Can not block the caller 10 iPhone iOS 7

    For some reason I seem to have lost the ability to block callers.  When I get a spam SMS and I click on the contact there is no option for calling block.  What gives?

    7 32 gb iPhone

    iOS 10.0.2

    Hey Toby,.

    I see you try to block people calling and messaging of your iPhone.  This feature is really handy, so let's first make sure you go through the right process, trying to block the numbers:

    Block the phone numbers and contacts or filter messages on iPhone, iPad, or iPod Touch

    Take care.

  • BLOCK the POPUP is supposed to stop some analyses online.  How to kill my popup block?

    BLOCK the POPUP is supposed to stop some analyses online.  How to kill my popup block?

    < email published by host >

    Safari > Preferences > Security > Web content:

    Uncheck "block pop-up windows".

Maybe you are looking for

  • iPod Touch 5 is disabled

    My iPod touch 5 is disabled for 45 years and I can't unlock it, I tried to look for ways to solve this but the only way to fix it is to erase from his memory, I valuable family photos on my IPod that I can't afford to lose, because they are the only

  • No menu bar when upgraded to windows 8.1

    I've never used Skype, but it came when I upgraded to windows 8.1. I am trying to delete the history of the previose cats and it seems I can do thanks to a menu bar. The problem is that I don't have a menu bar like I saw in the pictures when I was do

  • How to change the display of the list of recent jobs on lenovo vibe turned?

    Hi, I looked everywhere in the settings to find the way to change the display of list of recent jobs... I used to use the stacked styles, and out of nowhere, there is a menu to change the styles, now it displays the app recently opened next door... I

  • Limitation with the number of entries in a Tunnel of Split ACL

    Hey Cisco community! I am facing a problem with a Cisco hub and spoke to the solution. We have 2 Hubs (Cisco 7200-2 for redudancy). All clients have a RADIUS (Cisco 881). The rays are 24/24 reported the 2 hubs (2 dmvpn tunnel) to give us access to ou

  • Migration between vCenter servers, publishes the setting destination folder

    I'm having a problem with a migration script, I wrote to migrate virtual machines between 2 VCs.  The first part of the script works as expected (checking tools, right-size and removes the VM of the inventory on the VC source).  The second fails.on o