How can I show thru jlabel a variable that is modfied by several threads?

Dear all,
This is my problem, I have a variable, lets say m_money, m_money is been constantly modified by severeal threads, and it is also showed on my user interface using a jlabel componet, lets say m_jlabel_money. You have to take into account that if you want modify the state of a swing object with different threads you have to use something like invokeLater or another Swing utilities.
My question is how should I program my threads to modify m_money and m_jlabel_money at the same time without multithreading inconsistency?
I did this, but I am not sure if this is correct:
// function called by my threads
public synchronized void SetSaldoUsuarioMoneda(double money) {
          m_money=money;
          SwingUtilities.invokeLater(new ModifyJlabelState ());
//funtion which modify jlabel statte
     private class ModifyJlabelState implements Runnable {
              public void run() {
                    m_label_saldo.setText(m_money);
     }Is this correct?
Should I pass m_money to ModifyJlabelState thru its constructor or should I read m_money from ModifyJlabelState?
Is synchronized required or is it no sense?
Is this a better way or is going to fail bacause money variable may be different?
// function called by my threads
public synchronized void SetSaldoUsuarioMoneda(double money) {
          m_money=money;
          SwingUtilities.invokeLater(new ModifyJlabelState (money));
//funtion which modify jlabel statte
     private class ModifyJlabelState implements Runnable {
                  private double m_money;
                public ModifyJlabelState(double money) {m_money=money;}
              public void run() {
                    m_label_saldo.setText(m_money); // this m_money is/was what we had when we created this instance, so is this correct?
     }Well, I would like to know your opinions about this, because I don't know how should I solve this.
Thanks a lot.
Edited by: Ricardo_Ruiz_Lopez on Jun 24, 2008 1:01 AM
Edited by: Ricardo_Ruiz_Lopez on Jun 24, 2008 1:02 AM

Your first approach is incorrect. You either need to synchronize the 'setText' call or make m_money volatile.
Your second approach will work with the caveat that the value displayed on the label may be slightly out-of-date.

Similar Messages

  • How can I show the recipients of emails that are invisible now?

    My email screen shows the sender, the subject and the date and time but not the recipients? How do I get the screen to show recipients?

    There is a small icon at the far right end of the header bar. Clicking it brings up all column options. Check the columns you want displayed.

  • How can I show the chart in forms?

    Dear all:
    I want to create a line chart. I use the chart wizard and it is successful to create the chart. But, it can't show the chart when I run the form. How can I show the chart in form6i?
    Besides, I see a document that refer to 'OG.pll'.
    I can't find the OG.pll in form6i. Do I need 'OG.pll' to show the chart when I run the form? Thank you very much!!

    Hi Carlos,
    You can try to create a code node for check which signature to print.
    In global variable declare a variable ie named g_sign type TDOBNAME.
    Then pass this var to name of graphics &g_sign&
    please check and reply.
    regards,

  • How can i show a value into a MessageStyledText

    Dear all,
    Suppose i have a value in a variable i.e. number=10;
    how can i show this value into a MessageStyleText when page loads.
    please suggest.

    Gyan wrote:
    Mofizur,
    Get the value from the variable & Use the below code in PR.
    OAMessageStyledTextBean processCodeBean = (OAMessageStyledTextBean)webBean.findChildRecursive("<Replace with Bean Id>");
    if(processCodeBean!=null)
    processCodeBean.setText(pageContext,null);
    }Regards,
    GyanString employeeNumber = "10";
    processCodeBean.setText(pageContext,employeeNumber);
    OR
    processCodeBean.setValue(pageContext,employeeNumber);
    Thanks
    --Anil                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can we show data in rows when it is in Columns........

    I have strucked with a simple but a complex problem.
    I have a Report with data in vertical rows..need of the hour is how can we show that data into column structure.
    here is the table sample which i have in Database..
    Location      chrg_type    Effective_date
    xxxxxxx        xxxx          xx-xx
    thhis is the structure in effective date we have several months in it in a single column i want show the effective date or effective month in various columns instead of a single column.
    my required table is....
                                Effective_date     Effective_date
    Location      chrg_type     xx-xx              xx-xx
    xxxxxxx        xxxx          xx-xx
    any tough heads?????

    Hi Sunil,
    Your 1st problem is that you are going to need one more field to accomplish you goal. What type of data do want under your new date columns?
    Anyway, once you have that you need to move on to how to move the data out into columns based on date.
    Try something like this.
    0_Date = IF DATEPART('m',{tbl.Effective_date}) = DATEPART('m',CurrentDate) AND
    DATEPART('yyyy',{tbl.Effective_date}) = DATEPART('yyyy',CurrentDate)
    THEN {tbl.DataField}
    1_Date = IF DATEPART('m',{tbl.Effective_date}) = DATEPART('m',DATEADD('m', -1, CurrentDate)) AND
    DATEPART('yyyy',{tbl.Effective_date}) = DATEPART('yyyy',DATEADD('m', -1, CurrentDate))
    THEN {tbl.DataField}
    2_Date = IF DATEPART('m',{tbl.Effective_date}) = DATEPART('m',DATEADD('m', -2, CurrentDate)) AND
    DATEPART('yyyy',{tbl.Effective_date}) = DATEPART('yyyy',DATEADD('m', -2, CurrentDate))
    THEN {tbl.DataField}
    ... Repeat this process until you have all of the columns you need, following this format.
    Hope this works for you,
    Jason

  • Forms 6.0-- How can I show records in a block in different colours.

    In a multi record block, how can I show few records in one colour and few more in a different colour depending on a condition.

    Use DISPLAY_ITEM.
    This will change the visual attribute of the item in the current(!) record,
    set_item_property changes the attributes of the item in all(!) records.

  • How can I display char if a variable is null

    Hi All,
    How can I display char if a variable is null  in sap business object
    item name
    Office Visits
    Non-Emergency ED Utilization
    Non-Preferred Pharmacy
    above items are value and they are populating for this month but form next month "Inpatient Stays" a new item will add at database level
    i want to display this item with current month
    final result should be
    item name
    Office Visits
    Non-Emergency ED Utilization
    Non-Preferred Pharmacy
    Inpatient Stays
    i have tried with ISNULL function but it is not working
    please help i am using SAP BO 3.1
    Thanks in Advance
    Ranjeet

    You should be able to findout NULL using isnull([object]) function.. at report layer..
    Try with the below formula which should work for you
    =If Isnull(trim([object])) then "Inpatient Stays" else [Object]

  • HOw can i show a table(name given in parameters) in a report program

    I made a report in which there is a paremeter asking for a table name ....
    PARAMETERS TBLLE_NAME(10) OBLIGATORY.
    Now when I enter the table namke then how can i show its values....
    HINT:- We have to use fiels symbols....AND THE USER CAN ENTER ANY DDIC TABLE NAME having some records ...........

    You can display the contents of the DB table inputted using ALV.
    Pass the Structure name as the DB table name inputted.
    Use CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE to create the dynamic table of the same structure as the DB table passed.
    Once the above steps are done, the internal table with data can be displayed using ALV.
    Reward points for all helpful answers.
    Thanks,
    Balaji

  • How can I show album art in the mini player when playing songs from a plugged in iPhone?

    How can I show album art in the mini player when playing songs from a plugged in iPhone?
    When I play from my phone and switch to the mini player it's always showing the music notes in the thumbnaill. It'd be nice if it could get album art off of the phone.
    I'm on iTunes version 11.0.4.4

    He @mracole,
    it is very nice that you post a solution to complete the library with artwork for album's that do not have an artwork. Your solution perfectly addresses the problem for assigning artwork, BUT this thread is about CHANGING artwork for albums already uploaded into iTunes Match. Just try to replace for example a blue artwork cover for an album with a red one. If you made it in a simple way (without deleting the album from iTunes Match and local changes on the files with an external ID3-Application or 2 or more iTunes libraries on different Mac's) this is the right place to give a solution. I really tried for hours to change the artwork to make them visible in landscape cover flow mode on my iPhone5. In rare cases I made it, but then the covers sometimes where restored to the old onces - exacly how it is mentioned by Starhawk
    As long as there is no simple way to change the cover of an iTunes Match stored album (you can change title, artist and so on without hitting "update iTunes Match" over all distributed Library on different devices - this date will be synchronized almost instantly) I considered the behaviour from iTunes as BUGGY! For me the local artwork cache (and if there is any iCloud artwork cache - I don't know) do not interfere with iCloud. Even when I delete the whole local cache (album artwork music - everything) I do not manage to change the artwork.
    Regards from Munich, Germany

  • How can i show Bcc in my outgoing emails for Mac Lion 10.7.2

    How can i show Bcc in my outgoing email for Mac Lion 10.7.2  Bcc does not highlite in View.
    Noomee

    Reset the SMC: http://support.apple.com/kb/ht3964
    Should fix just this sort of thing.

  • How can I show a 0% range in the data value label on a bar chart thanks?

    How can I show a 0% range in the data value label on a bar chart thanks?

    I'm not sure what the question is. 
    I know that if you have a bar chart and one of the categories (X-axis) has bar (Y value) equal to 0%, no bar is plotted for that category. Even the addition of a stroke (line) around the bars doesn't make one appear for 0%.  The only automatic way I know of to make it look like there is data in that category is to add the value labels to the bars. Inspector/Chart/Series, select one of the bars on the chart, click on "value labels". Another method that is a workaround is to fudge the number a little in your table so that instead of 0% it is a very small %.  This will get you a thin line on the chart.
    But if your question is about the value labels (the numbers that display on or in the bars) and you are not getting one for a bar that is supposed to be 0%, it probably means your table doesn't actually have a 0% in the corresponding cell. A blank cell in the table will not get a value label.

  • How can I show all missing content in iTunes library?

    How can I show all missing content (ie. show the exclamation mark against each track)? I can restore the missing content but need to know what is missing without running each track.

    One way to identify the broken links in your library is to create this set of playlists:
    Lost & Found playlists
    Create a playlist called Found, select everything in Music and drag it into the Found playlist. Create a smart playlist called Lost matching All the rules Playlist is Music and Playlist is not Found. Your lost tracks will be in this playlist.
    Or use iTunes Folder Watch and enable its option to check for dead tracks on startup.
    tt2

  • How can I use the color adjustments interface that shows up for camera RAW on jpeg files?

    How can I use the color adjustments interface that shows up for camera raw on other files types? The HLS controls had the secondary color adjustments (6 colors instead of the 3). Plus, it had same vibrancy and a better Curves interface. Yesterday was the first time I imported raw into Photoshop CS5 and I got that really cool interface. What is that? Can I use that on other file formats?

    Actually I am using the Tradional Chinese Version, when I try to edit the jpg file with camera raw, the system shows that there is no camera raw plug-in. The cmaera raw never work.

  • How can I get rid of old books that I have deleted from my device? It still shows up as purchased books on "Icloud".

    How can I get rid of old books that I have deleted from my device but still shows up as "purchased books" on "Icloud". I don't want to see some of these books at all. I can sort by one that are PDFs and ones currently on device, but it still gives option to show those old titles. Does anyone know how to erase your "Icloud" history, please?

    Nooooooo! lol... If I want to download again I will, I don't want an electronic trail. Plus when I have Ibooks open, sometimes I will accidently hit the item and it will immediatly try to download it. The problem with that is that its "Time magazines Best Photos of 2012" etc and it locks up my IPAD cuz of sheer size of the book. So I would like it gone from the history. Isn't there a way to clear the history? 

  • Reg:How can we show non valuated stock in the system for the paid items?

    Hi All,
    Customer orders 100 boxes and pays to all material.But customers  are shipped the  required material as and when required.My client requirement is these 100 boxes should show as non valuated stock.
    How can we show these paid 100 boxes of material as non valuated stock in the sap? Is this functionality available in sap or it comes under requirement?
    Ex:Customer X ordered 100 boxes and he paid to all quantity.
         The customer X does not have space at his premises to keep the stock of 100 boxes.He just requests 20 boxes every monday or required quantity.Then company ships the required quantity to customer X.
    Now the requirement is that these 100 boxes should be shown as non valuated stock in the system.This should not used for other customers, should not work ATP functionality for these material quantity.This should show as reserved to this customer X
    could you share any ideas or solutions reg this..
    Thanks in advance,
    Regards....VM
    Edited by: vm on Mar 9, 2009 3:46 PM

    Hi Arnel,
    Thank you for giving valuable points.
    In consignment scenario,the stock is available at customer place not at company place.But ownership is company itself.
    But in this scenario,Customer is not having space to keep the total ordered quianty.So cutomer stock should be kept at company itself,customer requests the required quantity(for which he  already paid  for the total ordered quantity) as and when required.How can it suits in this scenario?Could you plz calirfy the debit memo to realize sales ?How it will be help ful?
    Thanks and regards...VM
    Edited by: vm on Mar 10, 2009 9:19 AM

Maybe you are looking for