Collection concurreny issue

Hi
I have an issue with probably concurrency. Look at the code below:
import java.util.HashMap;
import java.util.LinkedList;
public class TestStressMarketPriceUpdateProcessor {
  ObjectQueue objectQueue = new ObjectQueue();
  UpdateProcessor uP;
  class UpdateProcessor extends Thread {
    UpdateProcessor() {
      super("UpdateProcessor");
    public void run() {
      while (true) {
        Object o = objectQueue.getLastObject();
  class Updater extends Thread {
    Object lock = new Object();
    String num;
    public Updater(int num) {
      super("Updater " + num);
      this.num = String.valueOf(num);
    public void run() {
      while (true) {
        synchronized (lock) {
          try {
            lock.wait(1);
          } catch (InterruptedException e) {
            e.printStackTrace();
        objectQueue.putObject(new Object(), num);
  public class ObjectQueue {
    HashMap<String, Object> map;
    LinkedList<Object> list;
    Object lock;
    public ObjectQueue() {
      map = new HashMap<String, Object>(60, 0.9f);
      list = new LinkedList<Object>();
      lock = new Object();
    public void putObject(Object obj, String key) {
      synchronized (lock) {
        Object prevObj = map.get(key);
        list.remove(prevObj);
        map.put(key, obj);
        list.add(obj);
        lock.notify();
    public Object getLastObject() {
      synchronized (lock) {
        if (list.isEmpty()) {
          try {
            lock.wait();
          } catch (InterruptedException ex) {
            return null;
        Object lastObject = list.removeFirst();
        map.values().remove(lastObject);
        return lastObject;
  public TestStressUpdateProcessor() {
    uP = new UpdateProcessor();
    uP.start();
    int num = 50;
    for (int i = 0; i < num; i++) {
      (new Updater(i)).start();
  public final static void main(String args[]) {
    new TestStressUpdateProcessor();
}What i experience is that sometimes the removeFirst() method throws a NoSuchElementException.
In the first place i cant see how could that happen, since only synchronized block can remove elements in the code.
I also suspected memory concurrency issue, but no matter volatile, or synchronized List, the issue still happens sometimes.
Can anyone help show my whats the flaw in the code?
thanx
david

matra,
As I can see from you code, there is a main thread (TestStressMarketPriceUpdateProcessor) which tries continously to get object from the ObjectQueue
the ObjectQueue is another thread which is very fine.
There is another thread which is an updater thread. This thread populate the ObjectQueue.
All of the above leads up to a common resource which is ObjectQueue
The updater wait is too short which make the ObjectQueue always get populated and does not allow ObjectQueue to wait some time so I would do the following to the code ; I am not going to explain the changes; however, you can look and notice the changes by your self.
Please notice the while loop in the method getLastObject()
public class TestStressMarketPriceUpdateProcessor {
  ObjectQueue objectQueue = new ObjectQueue();
  UpdateProcessor uP;
  UpdateProcessor uP2;
  class UpdateProcessor extends Thread {
    UpdateProcessor(int updaterNum) {
      super("UpdateProcessor" + updaterNum);
    public void run() {
      while (true) {
             * No need to synchronize the  objectQueue
             * since the  objectQueue.getLastObject() is synchronized
           //synchronized(objectQueue) {
                Object o = objectQueue.getLastObject();
  } // UpdateProcessor
  class Updater extends Thread {
    String num;
    public Updater(int num) {
      super("Updater " + num);
      System.out.println("Updater-->" + num);
      this.num = String.valueOf(num);
    public void run() {
      while (true) {
        synchronized (objectQueue) {
          try {
              objectQueue.wait(1000); // give a chanc to wait sometime
               objectQueue.putObject(new Object(),num);
               objectQueue.notify();
          } catch (InterruptedException e) {
            e.printStackTrace();
  } // Updater
  public class ObjectQueue {
    HashMap<String, Object> map;
    LinkedList<Object> list;
    public ObjectQueue() {
      map = new HashMap<String, Object>(60, 0.9f);
      list = new LinkedList<Object>();
    public void putObject(Object obj, String key) {
      synchronized (this) {
        Object prevObj = map.get(key);
        list.remove(prevObj);
        map.put(key, obj);
        list.add(obj);
    public Object getLastObject() {
      synchronized (this) {
         while(list.isEmpty())  {
              System.out.println("I am empty I will wait....;Thread-->" + Thread.currentThread().getName());
          try {
            this.wait();
            System.out.println("wake up to check if I am empty");
          } catch (InterruptedException ex) {
               // Restore the interrupted status
              Thread.currentThread().interrupt();
         System.out.println("I am NOT empty....;Thread-->" + Thread.currentThread().getName());
         System.out.println("list size before-->" + map.size());
         Object lastObject = list.removeFirst();
        map.values().remove(lastObject);
        System.out.println("list size after-->" +list.size());
        return lastObject;
  public TestStressMarketPriceUpdateProcessor() {
    uP = new UpdateProcessor(1);
    uP.start();
    uP2 = new UpdateProcessor(2);
    uP2.start();
    int num = 5; // give a chance to see empty list
    for (int i = 0; i < num; i++) {
      new Updater(i).start();
  public final static void main(String args[]) {
    new TestStressMarketPriceUpdateProcessor();
}Regards,
Alan Mehio
London, UK

Similar Messages

  • Collective goods issue in production

    Hello All,
    We want to do a collective goods issue in production. Is there a chance in SAP that we can do a goods issue by supply area or MRP controller. We don't want to enter manually the group of production orders in MB1A or don't want to do backflush. Is there any way, please advice.

    Dear,
    In standard SAP are we issue the good In MB1A (261 Mov type) with reference to order and which having the reservation.
    The dependent requirements are planned as per BOM explosion. Item materials are issued against header material to complete header material production.
    Goods issue takes place against the production order at the start of the header material prod order.
    But MB26 will allow you to issue for serval orders,
    Hope clear to you.
    Regards,
    R.Brahmankar

  • Collective goods issue

    Hi
    Any collective goods issue for production order is there in standard SAP?
    I checked in MB1A, there i can enter only 5 production order using with reference to production order. Beyond that no option was there.
    So any option is there. pls.

    Hi,
    You can do it by T.code MB26.
    Regards,
    Dhaval

  • CS4 Master Collection Activation issue

    I have installed CS4 master collection on my 2 PC's.
    The first of these was a new build PC using Vista Ultimate 64bit, I installed Vista and CS4 on a RAID 0 array comprising 3 Sata drives. CS4 was then activated on this machine as well as my other machine.
    After a couple of days the RAID array started showing errors, which I believe was down to the poor nVidia drivers / onboard controller.
    Anyway I reinstalled Vista & CS4 onto a single drive, when it came to activating CS4 however I get a message saying the serial no. has already been activated on 2 machines.
    Now Adobes FAQ states that CS4 will recognise a reinstall on the same machine, however I think that because I have gone from a RAID array to a single drive then CS4 will not be able to detect this as the data will have been spread over the 3 physical drives.
    I have contacted Adobe support and am waiting on a response, in the meantime is there something simple I have missed?

    The RAID problem was with CS2.
    The OP's issue is that he didn't deactivate before reinstalling. Only
    Adobe can help and there should be a phone number to call for activation
    assistance on the activation denial screen.
    Bob

  • CS4 Master Collection Installation Issues

    I recently purchased a new Dell Studio Laptop and attempted to install the CS4 Master Collection last night.  There are 5 Application Disks total in the package.  It starts out fine, goes through the first disk, asks for the second (had minor issues with the 2nd disk being read by the lap top, but once it was recognized that installed as well), then when I insert the third disk, it gives me a screen that just says "exit."  At first I thought the additional two application disks may just be extra apps, but when going through my systems menu, many of the programs that should be there are not installed.  What is happening? And how do I fix it?
    Thank you

    I recently purchased a new Dell Studio Laptop and attempted to install the CS4 Master Collection last night.  There are 5 Application Disks total in the package.  It starts out fine, goes through the first disk, asks for the second (had minor issues with the 2nd disk being read by the lap top, but once it was recognized that installed as well), then when I insert the third disk, it gives me a screen that just says "exit."  At first I thought the additional two application disks may just be extra apps, but when going through my systems menu, many of the programs that should be there are not installed.  What is happening? And how do I fix it?
    Thank you

  • Windows Server 2012 Pooled Virtual Desktop collection GetVMstate issue

    I am trying to create a Pooled Desktop collection with my Powered off VM and it errors out The
    virtual desktop must be in a stopped state:  Could not identify the state of the virtual desktop.  Ensure that the RD virtualisation host server is available on the network and the virtual desktop is shut down
    In the debug logs it shows.
    Component RdmsModel: GetVMstate for Vm Win7_BaseVM failed with error 16386
    Component RDExceptionHandler: Could not identify the state of the virtual desktop. Ensure that the RD Virtualization Host server sunflower-1.HYPERQA.NUTANIX.COM is available on the network and that the virtual
    desktop Win7VMSF is shut down.
    Please help on resolving this GetVMState issue.

    Hi Krishna,
    Thank you for posting in Windows Server Forum.
    When you are configuring RDVH initially, please see that you have meet prerequisites. Remember that you need these pre-requirements:
    • Database based on SQL Server 2008 R2
    • Static IP Address for all Broker
    • Round Robin DNS
    • All RD Broker must be members of AD Windows Group (es. RDCB Server Group)
    • The group must be insert into SQL Server as sysadmin ONLY for the DB creation. After that DB will be created give the db_owner permission only for their DB
    More information.
    Windows Server 2012 R2: Unable Add New VDI Template
    In addition, we need all RD Broker must have the same SQL Native Client as main SQL Server (es. SQL Server 2012 SP1). The Connection Broker server's computer account MUST be a member of the local administrators group on the Virtual Host (RDS Host) machine and
    then reboot the server. Finally check the result.
    Windows Server 2012 Virtual Desktop Template Issue
    Hope it helps!
    Thanks.
    Dharmesh Solanki

  • Apex Collection Saving Issue

    Let me start out by saying that I'm new to the idea of using a collection in Oracle/Apex instead of straight DB work. That being said, I know the purpose behind it, and I believe the general idea of how to set it up and use it. That being said, I currently have an issue that I can't figure out.
    I'm working on trying to fix a program that was built by someone else who is no longer here, and they are using a collection to store data temporarily until the remainder of a survey is saved, which it then copies everything over to the database.
    I follow how the collection is created, how it is updated, and saved at the end. What I can't follow is that It is only saving part of the data when it is in IE, and NONE of the data when it is in Firefox.
    What I had done was I copied the regions from the other pages that are being used once a survey had already been created (yes, the pages are separate not by my design but it's too late to try and fix all of the current problems AND merge all the pages together. That'll be the next release, but I digress). Now I checked (and made a backup of the page thankfully) and as far as I could tell, copying the regions and items from the other page should have worked just fine since they were using the same item names. Sadly however, it stopped saving relapses.
    I checked an old version of the system, and I found the reason why. The version I am working on was apparently using the normal naming conventions of P86_RELAPSE_ID, etc, where it should have been P86_C001, etc. So, I went about the task of renaming (and updating the JavaScript that was running the page) all of the items. Well, I tested the system after only about 16 items and it saved perfectly! I was so happy. I started to apply the same changes to a few more, and the items I changed did not save. I checked and everything is setup correctly (item names, item settings, etc) so they should save the exact same way.
    So, I tried opening it in Firefox so that I could keep items side-by-side while I am comparing them, and I noticed that none of the data when I "saved" a collection was staying in Firefox, but it would "save if I did it in IE.
    I'm completely stumped at this point. Any help would be extremely appreciated. Thank you.
    (PS: I'm sorry if what I am asking isn't too clear. I'm asking two things. First, why aren't items that are setup exactly the same, and the names all match the update and add data for the collection, saving to the collection, while others are? And the second question, is why isn't anything saving using this method in Firefox.)

    The problem seems to have worked itself out.

  • Automatic Intercompany Payment/Collection postings Issue

    Hi All,
    We have an intercompany scenario where we need to make actual payments between two company codes: Both the Company Codes are in SAP and in Same Client.
    1) Intercompany receivables in company code A matching payables in company code B.
    2) Payment run in company code B generates a payment from company B to company code A.
    3) This payment run is supposed to create 2 idocs, 1. Out bound Idoc in Company B 2. Inbound Idoc. Which triggers a Posting (Dr. Bank Transitory Cr. Interco. Customer)
    I am able to generate the Outbound Idoc through F110 (Payment Run). But inbound Idoc. is not getting generated in Company A. I managed to post an incoming payment advice IDOC using the test tool WE19. I just copied the outbound IDoc changed the sending / receiving ports etc, and changed the direction field in the control record- it posted without problems.
    Necessary settings have been maintained in WE20, OBCA and OBDG and also in the Posting Rule.  But I am still not successful in creating an incoming idoc. through F110.
    WE20- Message Type REMADV & IDoc Type used is PEXR2002.
    kindly share the details
    Thanks & Regards,
    Vikram K

    Dear:
             I guess you trying to tell  that your company code deals with a customer A who
    is  your vendor B and that you want to set off your receivables
    against dues owed by you? If yes then please proceed as under
    I assume that your company code is yet to collect 600 $ from customer A
    whereas you owe 800 $ to vendor B.
    In customer master (control data screen), activate
    a check box called vendor (T Code:FD02 or XD02)
    Similarly, activate the check box called customer in the vendor master
    screen(T Code :FK02 or XK02)
    By doing so you have let SAP system know that your
    customer A is also vendor B. You have done this at client level and this
    relationship applies to all company codes dealing with customer A and vendor
    B which is your basic requirement.
    Now move on to the company code section of your customer master ( T code
    FD02 or XD02) and activate a check box called clearing with vendor. Do the same thing with
    your vendor master (T Code FK02 or XK02) and activate a check box called clearing
    with customer.
    This means that your company code wishes to set off receivables from
    customer A against dues payable to your vendor B.
    In F110 now you would be paying 200 $ to vendor B.
    Hopefully this will resolve your issue.
    Regards

  • Creative Suite 4 Master Collection Install issue

    Hi,
    Hopefully someone can shed some light on my problem...
    I have a brand new copy of CS4 Master Collection which I shelled out a lot of money but I am having problems getting past the first minute or so on the first install DVD!!
    I keep getting an error that says 'SYSTEM ALERT' The Minimum System requirements are not met'
    I am running Windows Vista with Service Pack 1 on a laptop with 2GB Ram and 1.73Ghz.
    1) Adobe state that 2Ghz is the minimum. Is this pretty strict or do you think I should be okay with the 1.73Ghz I currently have? Could this be one issue as to why the requirements are not met?
    2) I have removed all adobe products such as Acrobat, Flash Player, Flash Plug Ins, Adobe InDesign CS2 etc. Do I need to remove Photoshop 7.0, Dreamweaver MX and Flash MX too or are these not affected due to being original Marcomedia Products?
    I am not too sure why Adobe CS4 seems to think my requirements are not met??
    Can anyone shed any light on this? Am I missing something obvious?
    Any help would be appreciated
    Cheers

    Thanks both
    Karen - Yes, Vista Home Premuim
    Bob - i had to edit my last post on here as I did think I had SP1 installed but I am starting to think that I actually don't!!
    I checked my Windows Updates and it seems that SP1 updates since July 2008 have failed to install properly.
    When I check my system info it doesn't list SP1 anywhere on my PC.
    Anyway, I downloaded the Readiness Update file and ran that. All went fine. I then downloaded the 455Mb SP1 file and can't seem to get past the first 10mins of that. I just get an error 0x800B0100
    So, as it stands I cannot install SP1 and CS4 stays lonely and unused in it's packaging :-(
    Any other ideas? Or is this something I really need to take up with the people at Microsoft/Vista?
    Cheers

  • Automatic data collection evaluation issue

    We are currently evaluating several automatic data collection applications that we are planning to integrate with our Oracle Applications --- got most of the RFQ constructed using this template, http://www.highjumpsoftware.com/adc/Vertexera062503/
    but we want to make sure that all the system integration issues have been accounted for.
    Does anyone have any success stories/horror stories about integrating automatic data collection products with the ERP system
    Thank you!

    cfhttp is a good place to start.

  • CS5 Master Collection Installation Issue

    I have a 15in retina display mac running on mavericks. I recently ran a clean up software for my computer and it deleted all my adobe applications. When I try to install from the disk I get the error "installer failed to initialize" and adobe support advisor did not detect an issue. I've tried just about everything and I can't get it back. Any help would be much appriciated! I can supply any additional information you might need

    Hi Onsides,
    Please check the compatibility of CS5 Master collection with 10.9, it has not yet been tested.(http://www.adobe.com/store/en_us/popup/software/creativesuite/mastercollection5/systemreqs .html)
    Please go through this link & perform the steps, :-
    http://helpx.adobe.com/creative-suite/kb/troubleshoot-error-messages-bootstrapper-cs5.html #main_Installer_failed_to_initialize_
    Please let us know if it worked.
    Regards,
    Rajshree

  • Collection Update issue - Full Eval of collections and Several in Awaiting Refresh Status

    We are experiencing an issue where several collections has a Current Status of Awaiting Refresh. They have continued to stay in this status for 2 days. We've verified that no blocking exists in SQL, checked for a bad query and have
    performed a Site Reset. We have also noticed that when we restart SMS_COLLECTION_EVALUATOR it forces a full collection evaluation of every collection in our environment (~7900). We see 7900 items hit the coleval.box and we also see them queued for
    processing in the Colleval.log. Also, if we manually update the Collection Membership of a single collection (Awaiting Refresh or Ready) this also forces an evaluation of every collection in our environment. Any Ideas??? TIA

    Also think about how your collections are setup in terms of limiting. There could be a cascading effect.
    http://www.sysadmintechnotes.com/2013/09/11/the-effect-of-a-limiting-collection-full-update/
    Daniel Ratliff | http://www.PotentEngineer.com

  • Adobe CS3 Master Collection Install Issues

    Im at my whits end with this, I have got the master Collection on a disk, but when i try to install it opens the installer and the bar opens but then it just silent closes (no error messages) after a second or 2... without any progress...
    The details;
    System Specs:
    Dell Inspiron 1545 Laptop, Intel Core2 Duo Processor 2GHz, 3GB RAM and 320GB HDD
    Running Windows Vista Home Premium, Service Pack 1, 32bit Edition
    I have previously had Photoshop CS3 and Premier 6 installed, but i got rid of those prior to install attempt number one!
    What I have tried so far;
    - I have deleted all Adobe software off my computer, therefore it isnt a software clash.
    - I have tried turning my anti-virus off and on, so it isn't an anti-virus or firewall clash
    - I have tried all the recommended tips on the Adobe website
    - I have all the correct files for running the software, I have also tried running it on a different laptop, and it worked.
    - I ran CCleaner, and a registry cleaner, still nothing
    - I realised I forgot to get rid of Macromedia Flash... Promptly removed it; still nothing.
    I am really getting upset by this now (upset and angry)
    All tips would be much appreciated and I will be forever in debt to whoever solves this issue!
    Thanks
    Josh

    I have also had trouble uninstalling Adobe Photoshop CS3, as i said above i tried to get rid of it, however i couldnt remove it via the uninstall menu, so i deleted it from program files (and all other traces of photoshop i could find) however the option to unistall is still their, but when i try to uninstall it comes up with the error message that is attached...
    im assuming these 2 problems are linked... so help with this would be useful..
    thanks!

  • COllection Editing Issue

    I have a collection on our state K12 site (not yet published) that will not open the Feed Editor for editing content. When I click the "Feed" link, I get the framed site, but no content. I do not get any error messages. Anyone had something similar happen and find a way around the issue?

    Greetings from Tennessee;
    I encountered this issue when I was prepping our site for the transition to the new Site Manager environment. Unfortunately, I could never find a "work around". The problem seems to be with the Site Manager environment.
    Apple's engineers monitor this discussion and should respond promptly. All the best on getting your site up and running!
    Syd Rodocker
    Tennessee Department of Education
    itms://deimos3.apple.com/WebObjects/Core.woa/Browse/tbr.k12.edu-dz

  • Hi, collection migration issue

    I am working on sccm 2012 collection migration, I am receiving below error while migrating few collections.
    Query rule "Query is Invalid". the rule may be based on a hardware inventory class not
    collected at the destination, or be based on Configmgr extension which is not present at the
    destination or refers to collection like "SMS_CM_RES_COLL<CollectionID>"
    where as Configuration.Mof file is modified and it is imported in the CAS.
    Please help me to resolve this issue

    Hello Torsten,
    Sorry for the late reply,I checked the collection, System Resource class is used.
    Nope, no one client in the hierarchy reported the data.I tried few things by following few blogs
    I enabled AD discovery on the test site and Ran the migration.I tried to change the query and deploy,
    Nothing got worked...Please help me to resolve the issue.

Maybe you are looking for

  • Is there a way to seed the SaveAs value triggered by the digital signature

    Hello Everyone, I have a form going out to hundreds of people. When the form is completed, the last thing they do is digitally sign the form (which prompts them to save it), and then they click a submit button, which e-mails it to me. The issue I am

  • Acrobat Pro 9.0- Edits don't stick

    I often need to make adjustments to a PDF created by an automatic accounting process, and then email it to someone else outside my organization. Typically, it involves placing a solid white block (locked) over existing text, and typewriting over that

  • N96 since V12 update - can't change snooze time

    I'm having a problem with my N96 since updating to v12.043. Regardless of what I set the alarm snooze time to, the phone snoozes for 5 minutes. I've changed the snooze time in "Settings | General | Date and time" a few times, rebooted the phone, etc,

  • Macbook pro late 2012

    I own Macbook pro late 2012. I noticed fried chip near fan it has six connector, three on each side. Does anyone have clear photo of this side of the motherboard?

  • How to get bean information in EJB 3.0

    Hi all Can anyone tell how we can get the beans , I mean ejb beans related information deployed in the Netweaver AS programatically...  I am using EJB 3.0. thanks Rafi.