An addition/update of value and another thread getting values issue...

am using a spring (singleton) bean and this is what it looks like

public class MySingletonService {}

Private map < String, list < TaskVO > > alerts = new HashMap < String, < TaskVO > list > ();



Spring will call this method every 15 minutes
public void pollDatabase() {}


initialize the alert instance variable and create/fill the alert instance variable with new alerts for the employee (from database). The key of the hash table is the employee id
}




Some client code (for example the GUI) calls this method to get the alert for the id of the operator. This can be called at any time to get the latest news of the alert map
public list < TaskAlertVO > getOutstandingAlerts (String operatorId) {}
Return alerts.get (operatorId);
}
}

The problem here is that when getOutstandingAlerts is called by a thread, a few other thread (Spring) by calling the pollDatabase method can be updated value. Please give me some idea and solution to work around this problem.
I was thinking of creating a copy of the alert instance variable in the getOutstandingAlerts method and then use to find the key and return the alert for this id of the operator. This way we don't have to worry about data conflicts.

Please advice

Manjit wrote:

jtahlborn wrote:
If the pollDatabase() method gets a new full copy of alerts every time and map of alerts is not changed at all after the load, then you can simply:

-Check the alerts member variable volatible
-create a new HashMap is called whenever pollDatabase(), fill it in and then assign it to the variable member of the alerts.

Jtalhorn, I think I got your point. Basically you suggesting that by creating a new card for each operation of pollDatabase, then I don't have to worry about the get operation, simply because the client code is always looking at the old location (old copy) memory and therefore should not worry about the values of obtaining changes in method pollDatabase.

I got it.

But little doubt is that why should I even bother to make the volatile instance variable? Your suggestion should work without making volatile

because the volatile provides visibility of memory correct between the threads. If you don't use a volatile, a caller of getOutstandingAlerts() could see a partially initialized/corrupted version of the map.

Tags: Java

Similar Questions

  • Updated my computer and now I get no video on the screen change the first 10... I can't hear the audio.

    Prime Minister 10

    Windows 10

    GEforce GTX960 video card

    Updated by NVidia drivers

    The video on Windows Media Quicktime etc.

    I7 processor

    Reinstall the first 10 several times

    MOV files and WMV tried both without video

    Could be a similar problem

    https://forums.Adobe.com/thread/2082964?q=elements%2010%20VI

    Download ss14 and see if you still have the same problem.

  • I updated Firefox, restarted and now I get the following error message when I try to reopen Firefox. "The sqlite3_stmt_readonly of procedure not found entry into the dynamic link library mozsqlite3.dll."

    I just updated Firefox and restarted.

    Download a new copy of Firefox and save the file to the desktop.

    • Uninstall your current version of Firefox.
    • Do not remove the data of a personal nature when you uninstall the current version.

    Delete the program folder Firefox before installing newly downloaded copy of the Firefox installer.

    • It is important to remove the Firefox program folder to delete all the files and make sure that there is no problem with the files that were the remains after uninstallation.

    Your bookmarks and other profile data stored in the Firefox profile folder and will not be affected by a relocation, but make sure that you do not select delete data of a personal nature if you uninstall Firefox.

  • For v.15 auto update on TUE and now I get hangs (freeze XP SP3 completely) every few hours. Help!

    Question says it all.

    I think I should get off until bugs in v.15 are developed. How do I do that?

    It's good to know.

    For the moment, I think that maybe my problems were related to the material. Fixing the voltage of my video card seems to have solved my problems. Without blockages with Firefox since then.

    It seems that Firefox may only put a heavy strain on the video card is causing problems. Weird, but that seems to be compatible with all the symptoms. Not sure why v.15 would put more stress on the video card, but it may have been a coincidence.

    Icon problem seems to have disappeared as well. Can only assume that it was somehow connected.

  • 10.10.5 slow transformation after 13/09/16 auto updates installed! 20 min. to get this issue out! Any ideas?

    Ver.10.10.5 OS X Yosemite

    Updates to OS X Yosemite Ver.10.10.5 months made me back with an operating system that now the overloads of the processor with "out of memory of the application' opinion arise within the App to leave forced.  Just type this memory marked a step back to the old 286 days of treatment of 30 years, despite only active application!

    Any suggestions?  It seems as if underlying activity runs as hard as he can in circles endlessly, or as his attempt to sync with something permanently, but I run operations synchronization of any kind. I have 80GB free (250 GB) HD, 4 GB of DDR3 memory.

    Is there a diagnosis I can run to identify all actions through the processor. How can I identify what is eating a lot of time processor?

    It has been suggested that recharge Yosemite OS X.  Until this is resolved, the thought of this attempt at this speed of CPU is overwhelming and could dig a deeper hole to get out of. In addition, he was works perfectly until what updates of last month.

    Would appreciate any other suggestions

    Try to run this program in your usual account, then copy and paste the result in a response. The program was created by Etresoft, a regular contributor.  Use please copy and paste the screenshots can be difficult to read. On the screen with the Options, please open Options and tick the boxes in the bottom 2 before the race. Click on the button "Report share" in the toolbar, select "Copy to Clipboard" and then paste into a response. This will show what is running on your computer. No personal information is shown.

    Etrecheck - Information System

  • I just installed Java and now I get an error for the processing of JSP

    original title: JSP processing error

    I'm trying to understand what JSP processing error and how to fix them.  We just did an update for JAVA, and then we get this error.  I don't understand resource of portlets and permission.  How can I fix it?

    Hello

    1. could you give us the exact JSP error that you experience?
    2. Once you get this error message?

    Try to uninstall and reinstall the whole Java and check again. You can also seek assistance from support Java.
    http://www.Java.com/en/download/support.jsp

    I hope this helps.

  • In another thread - another method and then run Sub...

    I wrote a method to extract a string from a webpage using StreamConnection and it works perfectly... except that it runs on the main thread.  I wonder if there is a simple way to have a method that returns an object (String in this case) something to run on a thread and return it to the first thread.

    Everything I try the only thing I can get to work on the second thread is what's on the run method void, but that returns nothing... because it sucks...

    Until now what I thought is to pass the variables I need in the constructor, then set the connection stream real term where I want retruned is written in a class variable and another method that returns the class variable that has been filled with the run method... but that doesn't seem to just... thought he worked in a simple test I ran...

    A slightly different way (but completely equivalent) to work in a another thread is to create a class that implements Runnable and feed a thread. If, for any reason, you do not want to expand Thread (because your worker class extends already something else and it would be difficult to refactor), then this variant is a lifeline. You do something like this:

    class WorkerClass extends AnotherClass implements Runnable {    // ...    public void run() {       // do time-consuming work here    }}
    
    // later...WorkerClass worker = new WorkerClass();// initialize worker object. Then: new Thread(worker).start();
    

    As it is easy to turn a class in an executable (you simply add "implements Runnable" and a run() method), it's an easy way to avoid the subclassing Thread.

    Regardless of how you use to perform work in a separate thread, there is always the question of how to get the results. With the help of the observer is a common way to handle this, but in general, this means that the results are returned in the worker thread, not the thread from the main event. If you want to update the user interface, this can be a problem. Another approach is to structure your code something like the following:

    /** * Process the results of some time-consuming operation. */public void acceptResults(ResultType result) {  // ...}
    
    /** * Start a thread to carry out time-consuming work in a * separate thread and deliver the results back in the * event dispatching thread. */public void launchWork() {  new Thread() {        public void run() {           final ResultType res = computeResults();          Runnable r = new Runnable() {                public void run() {                   acceptResults(res);               }         }         Application.getApplication().invokeLater(r);      }
    
           /**        * Do time-consuming work in this method       */       private ResultType computeResults() {         // connect to server, interpret reply, etc.       } }.start();}
    

    You have the right idea that is running in a thread separate is how to manage a time consuming task. The point of all, however, is that you (the event dispatching thread) don't want to wait for the task at hand. Both the observer model and the code here offer a solution for a worker thread to do the work without blocking the thread of the event. The invokeLater() method was kindly provided by BlackBerry people to give the worker threads neatly transfer control on the event dispatching thread when needed.

  • Update the values in the Table from another Table containing historical data

    So, I have two tables, a table and a master table.  The current table is updated each week and at the end of the week, is copied to the main table to keep historical data.  I have update the table in progress early in the week and want to take the latest data from the master table and update the current table with the data.  The current table could have additional IDs or some of the IDS could have deposited (these lines would receive data in the main table).  I want to only update the rows in the current table that have existing data to the attr1, attr2, attr3 columns.  A particular ID may have more than one record in the primary table, I want only the last disk to use for updating the current table.  The data from a different database where no direct connection is possible then I have to import data every week.  Here are some statements of create/insert:

    create table current_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
    

    create table Master_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
    
    

    begin
    insert into current_T (ID1,adate)
    values ('IE111','08/02/13');
    insert into current_T (ID1,adate)
    values ('IE112','08/02/13');
    insert into current_T (ID1,adate)
    values ('IE113','08/02/13');
    
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE111','08/01/13','yes','abc','123');
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE112','08/01/13','no','dgf','951');
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE113','08/01/13','no','dgf','951');
    insert into master_T (ID1,adate,attr1,attr2,attr3)
    values ('IE113','07/01/13','no','dgf','951');
    end;
    

    This has been a scratcher for me head and any help would be greatly appreciated.  I'm coding in Apex 4.1

    Thank you

    -Steve

    Not tested

    merge into current_t c

    using (select *)

    Of

    (select m.*

    row_number() over (partition by m.id1 m.adate DESC order) rn

    of master_t m

    )

    where rn = 1

    ) u

    on (c.id1 = u.id1)

    When matched then update

    Set c.adate = u.adate

    c.attr1 = u.attr1,

    c.attr2 = u.attr2,

    c.attr3 = u.attr3,

    When not matched then insert

    (c.id1, c.adate, c.attr1, c.attr2, c.attr3)

    values

    (u.id1, u.adate, u.attr1, u.attr2, u.attr3)

    ;

  • I have the Windows Vista operating system. Whenever I connect my computer, I get two pop ups on the taskbar. One is jucheck.exec and another is updates of Java.

    I have the Windows Vista operating system. Whenever I connect my computer, I get two pop ups on the taskbar. One is jucheck.exec and another is updates of Java.

    I have no way to uncheck the premiera. I have only two options, restore or close. With java, I opened the properties and click to remove the check mark from updates, you click on apply and then clicked on ok, but he still continues to appear you have tips on how can stop these pop ups?

    Hello

    I would like to inform you that Jucheck.exe is the process that runs automatically when the Java Update tool is activated. Jucheck.exe usually checks the Internet for the software updates available and invite you to install them to keep your updated program. If you prefer to search and download the Java updates manually whenever you want, disable Java Update automatic tool disables and removes Jucheck.exe

    It will be useful. For any other corresponding Windows help, do not hesitate to contact us and we will be happy to help you.

  • I transferred my Lightroom 5.7.1 my cell phone to my PC. I put in the serial number, you press "next" and another box came up saying that the updated code was for and upgraded version and I should put in the old version the serial number - this I can't f

    I transferred my Lightroom 5.7.1 my cell phone to my PC. I put in the serial number, you press "next" and another box came up saying that the updated code was for and upgraded version and I should put in the old version the serial number - this that I can't find

    you will need to this previous version number and serial number.

    If you purchased the previous version of adobe or registered with adobe, check your account: ID Adobe

    in otherwise, find the serial number of your product Adobe quickly

  • If I create a website for a client, it will be able to update certain content using another tool for Adobe (it won't use (and buy) DW just few updates)?

    If I create a website for a client, it will be able to update certain content using another tool for Adobe (it won't use (and buy) DW just few updates)?

    Why not contribute? Always sold, my clients love it. Each of them made. They all hate wordpress and Joomla, and when they try to contribute, they all thank me. I don't even have to teach them how to use it.  But if they do not spend a penny on any software, then you're kind of stuck.

    There is a CMS for Dreamweaver by Studio extend I think. I bought it, and it is not very good in my opinion. It is not integrated in the system uses DW model, then you will need to open each page and select a div at a time to make editable manually. Could be so much more. I think it's a domain Adobe completely blew with DW.  Absolutely, there should be an integrated way in order to offer a type CMS without Contribute workflow. Having to use WordPress is not something that I like. Most of my clients is a small business and need one, maybe 2 people to make fundamental changes to their pages. Built in CMS would be perfect. I continue to use DW to build sites, and I could let minor things without a disbursement of $200 for the customer.

  • How to update a table and insert into another

    I need to update a table and also to insert into another table and want to do it in the same form. I can it will break in 2 different forms, but it is awkward for the user. Is there a way common to this address? As a backdrop, the user is updated the status of a message (IE, changing it from open to closed) and then provide an answer. The response table is separate from the table of messages because its format is doing different.

    Thank you and sorry to bombard the forum today.

    .oO (davidbarrackphoto)

    > I need to update a table and also to insert into another table and want to
    > do it in the same form. I can it will break in 2 different forms, but it is
    > awkward for the user. Is there a way common to this address?

    You can do what you want in your form processing script. But for
    much more advanced than you must write your own code.

    > As a backdrop.
    > the user updates the status of a message (IE, changing it from open to closed)
    > and then provide an answer. The response table is separate from the table of messages
    > because its format is doing different.

    Just curious: what is the difference? IMHO, there should be only one table
    for messages. Can you post more details about it?

    Micha

  • Firefox opens with a window that says "Check to ensure the compatibility of Add-ons" then he opens always 2 tabs... one with my homepage and another that said congratulations, Firefox is updated. How can I prevent the it starts like that?

    Firefox opens with a window that says "Checking for compatibility for modules" then he opens always 2 tabs... one with my homepage and another that said congratulations, Firefox is in place

    Rename the files work perfect! Thank you

  • can not access the internet even if my wifi connection status is "enabled", I go to another user and am connected, get updates and others and have the ability to nav.

    Windows 32-bit Vista on a HP laptop, wifi is on State is enabled and still on the past of the main user unrelated real, even when the State is supposed to be activated, I went my way, any other user and get the updates to download and other connect ability.  Can someone help me change it's for a 76 year old mother, who gets very nervous sometimes with the laptop that I gave him, help me please... Stevielee

    Hi Stevielee,
     
    1 you get an error message when trying to go online?
    2. what web browser do you use to go online?

    You are able to go online to a different user account. There must be a problem with the settings of the web browser. Try these steps and check the result.

    Step 1: Reset the Internet Explorer settings.
    1. Click Start, type inetcpl.cpl and press to enter.
    2. click on the tab advanced and then click Reset.
    3. click on reset.
    4. When you are finished, click Close, and then click OK.
    5. close Internet Explorer and reopen it before the changes take effect.
    6. check internet connectivity.
     
    NOTE: Reset the Internet Explorer settings can reset security settings or privacy settings that you have added to the list of Trusted Sites. Reset the Internet Explorer settings can also reset parental control settings. We recommend that you note these sites before you use the reset Internet Explorer settings.
     
    For more information on "Tips for solving problems with Internet Explorer", visit this link:
    http://Windows.Microsoft.com/en-us/Windows-Vista/tips-for-solving-problems-with-Internet-Explorer

    Step 2: If the problem persists after you follow step 1, try to correct the user account.
    Difficulty of a corrupt user profile: http://windows.microsoft.com/en-US/windows-vista/Fix-a-corrupted-user-profile
     
    Try the steps and post back with the results, so that we can help you further.
     
    Kind regards
    Syed
    Answers from Microsoft supports the engineer.

  • Installed Vista Update 1 package and now windows will not start

    I have a laptop Acer Aspire 4520 with a 32-bit system 64 x 2 dual core processor with Windows Vista Home Premium and just installed explorer8 updates Vista I get the package. Installed successfully, took about 45 minutes. Tells me to restart my computer. Click on restart. It restarted with goin' through bunch of # s as the first part 24 390 / 74 280 in growing in order to achieve the final number that it stopped at about 34 761 or something like that for over an hour.  I assumed that it froze. I did a hard closed down and after reboot door top, unable to start Windows.  A recent hardware or software change might be the cause and options to start windows normally or start the reboot system (recommended).  I chose normally, microsoft corporation logo came on screen with progress/cargo in addition to this box, and then it turns off and rebooted itself.  This time I chose the launch startup repair and he went to remove some threads or something and add as 9 things that did not file names.  He said he was doing a CLNDSK?  It was the only time he's done this. Now, either you the hit button brings up a blue screen that says "a problem has been detected and windows has been shut down windows to avoid damaging your computer."  If this is the first time you've seen this stop error screen, restart your computer.  If this screen appears again, follow these steps: ensure that new anuy hardware or software is properly installed.  If it is a new installation, ask your hardware manufacturer or software, the windows updates, you might need.  If problems continue, disable or remove any newly installed hardware or software.  Disable the BIOS memory options such as implementing caching or shading.  If you need to use Safe Mode to remove or disable components, restart your computer, press F8 to select advanced startup options, and then select Safe Mode.  Technical information: * STOP: 0x0000C1F5 (0x00000000, 0x00000000, 0 x 0000000 0x00000000) is once again this whole message on a blue screen in which you can proceed to any other, but to stop the machine.  I even tried the advanced, including Boot Options: repair your computer, safe mode, safe mode with networking, safe mode with command prompt Mode Mode Mode, boot logging, enable video low resolution (640 x 480), last good known Configuration (Advanced), Directory Services Restore Mode, Debug Mode and start Windows normally.  Disable the automatic restart on system failure works.  Another option is the F2 key on startup.  I CAN'T go near a window to start it's totally out!  And I do NOT have a disk of Vista, that it came with it.  Need solutions before I go out my hair.  (Good operating system until the download and I only downloaded this because I download Adobe Flash Player 11.2 problems and I thought about updating my Windows can help)  Ready to take this computer back unless it is quickly fixed.

    .. .just for a future heads up what should I update on a new system from Microsoft.

    All the day of security offered by Windows Update/Automatic Updates. See http://windows.microsoft.com/en-us/windows7/Updating-your-computer

Maybe you are looking for

  • HP dv6-2150us-driver missing

    I use windows pro 8.1 on this old laptop. Recently, I checked the Device Manager and found 2 lack of drivers, that I tried use booster driver to install the missing drivers, but I did not. Here are the pictures:

  • After Windows 7 SP1, no drivers found

    I have a DSR-PD170. Everything was going fine until Windows 7 upgrade itself to SP1. I have Windows 7 Pro x 64. Can I use the fire-wire and it recognizes usually but now anything and after extensive research I can not get my camcorder to find a drive

  • HP mini 1035NR drivers are missing

    I just bought this netbook mini 1035NR hpn on ebay and I'm guessing that the person has erased the drivers and I wonder what I come vthem. I'm missing -Audio device on High Definition Audio Bus -Bluetooth 2.1 module -Ethernet controller -Network cont

  • I installed a freeware program called "truecrypt" and have a problem with the startup.

    I've since deleted, but when I start my computer it starts with the bootloader "truecrypt". I can start my computer, but only after I press "ESC" to bypass the boot loader. The bootstrapper calls the password I put in place, but forgot since. I can't

  • Boot Manager displays 3 systems

    Presario C300P / N:RE027PA #AB0Service C304TUOS: Windows 7 Pro. 32 b. Only Windows 7 Pro. is installed but the Manager startup displays 3 systems. I tried to get rid of those extra but not been able to find how. Help, please. Thank you.