One thread adding/updating value  and other thread getting values....issue

am using a spring bean (singleton) and this is how it looks like
public class MySingletonService {
private Map<String, List<TaskVO>> alerts = new HashMap<String, List<TaskVO>>();
//spring will call this method every 15 minutes
public void pollDatabase() {
//initialize the alerts instance variable and create/fill the alerts instance variable with new alerts for the employee(from database) .The key for the hashmap is the employee id
//some client code (e.g. GUI) will call this method to get the alert for the operator id.This can be called anytime to get the latest info from the alert Map
public List<TaskAlertVO> getOutstandingAlerts(String operatorId) {
return alerts.get(operatorId);
The issue here is that when getOutstandingAlerts is invoked by a thread,some other thread(Spring) calling the pollDatabase method might be updating the value.Please give me some idea and solution to get around this issue.
I was thinking of creating a copy of alerts instance variable in the getOutstandingAlerts method and then use the copy to find the key and return the alert for that operator id.This way we dont have to worry about data conflict.
Please advice

Manjit wrote:
jtahlborn wrote:
if the pollDatabase() method is getting a complete new copy of the alerts every time, and the alerts map isn't being modified at all after load, then you can just:
- make the alerts member variable volatible
- create a new HashMap each time pollDatabase() is called, fill it in, and then assign it to the alerts member variable. Jtalhorn,I think I got your point.Basically you are suggesting that by creating a brand new map in each pollDatabase operation, then I dont have to worry about get operation ,simply because the client code is still looking at old memory location(old copy) and hence should not worry about values getting changes by pollDatabase method.
I got it.
But the small doubt is that why even I should bother about making the instance variable volatile ? Your suggestion should work without making it volatilebecause volatile ensures correct memory visibility between threads. if you didn't use volatile, then a caller to getOutstandingAlerts() could see some partially initialized/corrupt version of the map.

Similar Messages

  • Difference between main and other threads

    There are a lot many tings you cannot do n the main thread( the thread running the main Method) and other Threads how exactly do they differ?

    Why doesn't it allow running the static methods from
    main like dumpStack( )....You can run static methods from main. Do you mean the main thread or the main method?
    You can't call non-static methods directly from the main method, but that's just because it's static. You can't call non-static methods from any static method, without an instance on which to call them. Nothing special about main in that respect.

  • SUP - Update KB3000850 and other issues

    Hello,
    I manage a SCCM 2012 R2 Infrastructure.
    I am trying to add the KB3000850 to my update package and I always get an error message.
    I tried to resynchronize the SUP and still the same error.
    Package:
     Success: The software updates were placed in the existing package:
    Software updates downloaded from the internet
     Success: Update for Windows 8.1 for x64-based Systems (KB3000850)
     Error: Update for Windows 8.1 (KB3000850)
    Errors
    Failed to download content id 16836098. Error: There was an error downloading the software update. (12002)
    Failed to download content id 16836099. Error: There was an error downloading the software update. (12002)
    Language Selection:
    English
    Also,
    - Some of the updates I deploy get stuck at 50% and the only option is to install the update manually...
    - The update installation is very slow compare to a manual install
    Have you already had those issues and how did you solve them ?
    Thanks.

    Hi,
    The error 12002 means timeout.
    Please check Patchdownloader.log to find more information.
    There is a similar thread that the issue was related to proxy.
    There was an error downloading the software update. (12002)
    You could also check the Gerry's comments about this error in the blog below.
    ConfigMgr 2012 / SCCM 2012 SP1 Step by Step Guide Part 16: Software Updates (Non-Microsoft)
    Note: Microsoft provides third-party contact information to help you
    find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.
    >>Some of the updates I deploy get stuck at 50%
    You could check reports in the console and logs on the clients to find the reason.
    http://technet.microsoft.com/en-us/library/hh427342.aspx#BKMK_SU_NAPLog
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Reg : Pass One Component's value to other component's value

    Hi all,
    I have the following code . Here I want to Pass :Pass One Component's value to other component's value
    <af:image binding="#{backingBeanScope.backing_OText.i1}"
    id="i1"
    source="#{(SkinBean.skinFamily == 'MSIE_D2I3')?'/images/d2i3Logo.gif':'/images/UDR_logo.jpg'}"
    shortDesc="Hello World"/>
    <af:spacer width="100" height="10"
    binding="#{backingBeanScope.backing_OText.s1}"
    id="s1"/>
    <af:outputText
    binding="#{backingBeanScope.backing_OText.ot1}"
    id="ot1"
    inlineStyle=" font-weight:normal; font-size:32pt; font-family:Georgia, 'Times New Roman', times, Serif;"
    value = *"Here I want to pass the value as 'Hello World' from The Image Component's ShortDesc"*
    Please give me the solution .
    Thanks inAdvance .

    since you already have the backing bean, you can try to set the value property to
    #{backingBeanScope.backing_OText.i1.shortDesc}regards,
    ~Krithika

  • Apple - please announce some guidance as to when devices running Lion 10.7.2 will automatically update Pages (and other iWork) docs via iCloud so that they appear updated in iOS5 devices?

    Apple - please announce some guidance as to when devices running Lion 10.7.2 will automatically update Pages (and other iWork) docs via iCloud so that they appear updated in iOS5 devices?  

    Same problem here after update to 10.7.3 and I need to manually set the wireless. If I disable wireless and reable it again the wireless connects ok

  • I added a counter and other html to my non .mac site

    I added a counter and other html to my non .mac site by simply adding the code to the index.html page after I published to folder.
    http://www.the-scrap-yard.net/photorestoration/

    Also, I would suggest requesting a change in your credit card number that was
    used for that transaction just to be safe.
    Also, since they actually got access to your computer, if you have any other
    financial account info on your computer, you will need to monitor those accounts
    quite closely for any fraudulent activity.  There is no knowing what they might have
    accessed.  They quite possibly may have downloaded your whole life.

  • I bought over a Mac Book Pro from a friend. I can't update iPhoto and other apps as it seems like these are tagged to the previous owner's account. Pls advise.

    I bought over a Mac Book Pro from a friend. I can't update iPhoto and other apps as it seems like these are tagged to the previous owner's account. It basically requires me to sign in to my fren's account which is absurb! Because iphoto comes with mac isn't it?

    Contact your "friend." Have him set up the MBP for your with your own account, settings and passwords. You are not running IOS 5.1. That is for iPhone and iPad users. What OS are you running? Did he give you the OS installer disks?

  • HT1338 Being prompted to update iPhoto and iMovie, but getting message "To update this application, sign in to the account you used to purchase it."  My email has not changed.  Any ideas?  -gb

    I am being prompted to update iPhoto and iMovie, but getting the message: "To update this application, sign in to the account you used to purchase it."  These came already loaded on my laptop, and my email has not changed.  Any ideas or work-arounds?

    Has your Apple ID changed, that's the one that matters.
    You need to sign in under the account that purchased these apps (did you buy this Mac new)

  • In imovie 10.0.1 while trying to update projects and events in get a box telling me iMovie could not find any projects or events to update

    in imovie 10.0.1 while trying to update projects and events i get a box telling me that imovie could not find any projects or events to update. Help, please.

    Do you have Projects and Events form an earlier version of iMovie?
    Matt

  • After just installing OS10 Yosemite v10.10.1 and try to open Photoshop CS5, I get a message saying 'To open "CS5ServiceManager", you need to install the legacy Java SE 6 runtime.' I updated to Java 8 update 25 and I still get the same message when I try t

    After just installing OS10 Yosemite v10.10.1, I try to open Photoshop CS5 and get a message saying 'To open "CS5ServiceManager", you need to install the legacy Java SE 6 runtime.' I updated to Java 8 update 25 and I still get the same message when I try to open CS5. What do I need to do in order to open and use Photoshop CS5 using Yosemite? Thank you for your help

    Here it is: Apple Java 2014-001.

  • Was forced to install Adobe again (maybe just update it) and can't get past step 3/3 because its forcing me to buy it. now its half installed and i need to agree to terms and conditions..

    was forced to install Adobe again (maybe just update it) and can't get past step 3/3 because its forcing me to buy it. now its half installed and i need to agree to terms and conditions..

    Let's start with what you are trying to install. Adobe Reader is free, so it won't be forcing you to buy anything. So
    - What are you trying to install (full name, please, Adobe make lots of things)
    - What system (e.g. Windows 7, Mac OS Lion, iPad...)
    - Where do you go (what web address) to start off?
    - Why were you "forced" to do this?

  • How can i do with labview program,when i have 20 different values,and 1 want to add it with constant value.and how to get the results?

    how can i do with labview program,when i have   20 different values,and 1 want to add it with constant value.and how to get the results?

    Why do the 20 values have to be different? The same code should work even if some are equal.
    What do you mean by "get the result"? The result is available at the output terminal and all you need is a wire to get it where you need it. That could be an indicator, another operation, or even a hardware device.
    What is the data type of the 20 values? An array? A cluster? A bunch of scalars? A waveform? Dynamic data?
    LabVIEW Champion . Do more with less code and in less time .

  • Good night,  I ended up making a purchase at Apple, but my credit card operator called me to confirm the values ​​and was told different values ​​than bought.  Purchases appeared as:  $ 159.70 (protocol 604627) $ 137.00 (protocol 604538) $ 105.39 (protoco

    good night,
    I ended up making a purchase at Apple, but my credit card operator called me to confirm the values ​​and was told different values ​​than bought.
    Purchases appeared as:
    $ 159.70 (protocol 604627)
    $ 137.00 (protocol 604538)
    $ 105.39 (protocol 604468)
    $ 0.01 (protocol 615633)
    Could you check what is happening? Because I had to cancel my card for security.
    Sincerely,

    np33td33 wrote:
    My purchases were:
    macBookPro
    office 2011
    iwork
    ilife
    and these purchases did not appear in the system credit card
    Call Apple at 1800MYAPPLE.  We just deal with MacBook Pro issues, and we have nothing to do with Apple.  Please read what others have posted.

  • I have purchased a 3gs and its jail broken. i tried to update it and it did get update also but it is not working, and techinal person said it is a locked.now how do i factory unlock it?

    i have purchased a 3gs and its jail broken. i tried to update it and it did get update also but it is not working, and techinal person said it is a locked.now how do i factory unlock it?

    It is not always possible to return a jailbroken phone to a pristine state. Jailbroken devices can NOT be discussed here per the terms of service. As for unlocking. It was previously hacked and has re-locked to the original carreir. ONLY the carrier it is locked to can authorize unlocking it. Find out who that is and contact them or do as steve359 advised above and try to return it for your money back.

  • The select function in Pages and other apps gets stuck and the cursor will not move. What do I do?

    The select function in Pages and other apps gets stuck when I touch a word and the cursor will not move. What is the answer for this problem?

    Try reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

Maybe you are looking for

  • How can we make disable a Field of a FORM at run-time?

    Hi to everybody, I want to know that how can we make a filed DISABLE at runtime <whenever we run a FORM>. I know about SET-ITEM-INSTANCE-PROPERTY but don't know how to use it, please make it clear. I will be gratefull to all of you Thanking you in ad

  • Playback issues with iTunes Match on iPhone 4 (iOS 5.0.1)

    I'm running into several odd issues when playing songs on my iPhone with iTunes Match enabled. The problems I've experienced are: A song partially plays, then skips to the next song. Sometimes songs will not pause, pause after a 2-3 second delay, or

  • I downloaded latest iTunes and OS and now cannot open iTunes Store or Synch my iPad. Any suggestions

    When I last uploaded the latest firmware I was not able to open the iTunes store. After being told it must be a firewall issue Apple finally told me that a number of people complained about the same thing. They told me to completely remove iTunes, Qu

  • User hierarchies

    Hi all, Can anyone plz help me with the following In the SAP system a user can operate in the following hierarchies. (a)     Service level. (b)     Application level. (c)     Main menu level. (d)     Month. (e)     Total stock value. which options ar

  • Abstract classes in  AS

    Hi, are there abstract classes in Action Script (or abstract methods)? Thanks, Stephanie