Thread FAQ:findind removed collection elements

Hi All
i have two threads and one collection with some elements ,The problem is one removed some elements in collections now i want to find out elements removed by thread one with thread two

Well they're not in the collection any more, are they? so the thread that removed them will have to remember them somewhere, or else the other thread will need a copy of the original collection.
It's not a Thread FAQ question. Any two classes that used the collection would have the same issue.

Similar Messages

  • Kill a thread and remove the element from the vector

    Hi All
    I have attached each Vector element to a thread which I later want to kill and remove that element from the Vector.
    Thread.join(milliseconds) allows this functionality to let the thread die after n milliseconds.
    However, I want to delete this element from the Vector now.
    Can someone please throw some light on this?
    Here the code I have written for this:
    try
         System.out.println(counter);
         int xCoord = generator.irand(25,200);     // X-coord of AP
         int yCoord = generator.irand(25,200);     // Y coord of AP
         listMN.addElement(new MobileNode((int)mnId,new Point2D.Double(xCoord,yCoord)));
         listMNcoords.addElement(new Point2D.Double(xCoord,yCoord));
         for(int i=0;i<vnuBS.returnBSList().size();i++)
              if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=3)&&(vnuBS.returnBSList().get(i).getChannelCounter()>0))
                   double c = exponential() * 10000;
                   long timeToService = (long)c;
                   System.out.println("BS "+vnuBS.returnBSList().get(i).id+" is connected to MN ");
                   vnuBS.returnBSList().get(i).reduceChannelCounter();
                   System.out.println("Channel Counter Value Now: "+vnuBS.returnBSList().get(i).getChannelCounter());
                   mobileNodesThread.addElement(new Thread(listMN.elementAt(mobileNodeCounter)));
                   mobileNodesThread.elementAt(mobileNodeCounter).setName(mobileNodeCounter+"");
                   mobileNodesThread.elementAt(mobileNodeCounter).start();
                   mobileNodesThread.elementAt(mobileNodeCounter).join(100);
    //                              System.out.println("Died");// thread dies after join(t) milliseconds.
                   System.out.println("ListMN getting generated : " + mobileNodesThread.get(mobileNodeCounter));
              else if(vnuBS.returnBSListCoords().get(i).contains(xCoord,yCoord)&&(vnuBS.returnBSList().get(i).getChannelCounter()<=0))
                   listMN.remove(this.listMN.lastElement());                         //dropcall
                   System.out.println("Removed "+mnId);
                   removeCounter++;
                   mnId = mnId--;
                   mobileNodeCounter--;
              mnId = mnId+1;
         Thanks a lot.

    I'm not sure if what you are trying to accomplish is correctly implemented.
    The method join does not kill the thread. It will wait for the specified time for the thread to exit. If you want the thread to run for a specified ammount of time, develop the run method of that thread with that in mind. Do not try to kill it from the outside, but let it terminate itself (gracefull termination).
    Now for your question regarding the vector (you should probably be using ArrayList nowadays): I would implement the observer pattern for this job. Make the threads post an event on the interface when they are done, let the main thread register itself with the threads and synchronize the method that handles the events. In that method you can remove the object from your list.
    I'm not sure if you want to use thread anyhow, could you tell us what it is that you are trying to accomplish?

  • Removing specific element from a list

    Hello, I'm very new to java, and to programming in general.
    I'm trying to write a secret santa app for my family for christmas. Essentially the idea is that 7 names are put into a list, and each time a name is "pulled" (i.e. randomly assigned to a name /= itself) it will be removed from the list of available names to assign.
    String[] nList = { name2, name3, name4, name5, name6, name7 }; // store names for random use
    Random r = new Random();
    name1assign = nList[r.nextInt(nList.length)];
    String[] nList2 = { name1, name3, name4, name5, name6, name7 };
    name2assign = nList2[r.nextInt(nList2.length)];
    My goal for this is to take the string that is equal to name1assign, and remove an element with that string from nList2.
    Can anyone give me some advice in this matter?
    Thanks.

    Sometimes a null value is used to indicate an 'empty' array element, but it would be better to try collections instead.
    You could use an ArrayList instead of an array. This has methods to remove items by index or value.
    An ArrayList also works with Collections.shuffle, which allows you to simply iterate over the list and not deal with random or removing elements at all.

  • What would happen if two concurrent threads try and remove ....

    Hello,
    I have a java test to give back tomorrow and I'm stuck on this question, could you help me please.
    Question: What is the difference between java.util.Vectorand java.util.ArrayList?
    I read everywhere that: The main difference between Vectors and ArrayLists is that Vectors are synchronized so any method that touches the Vector’s content is thread safe, which is not the case for ArrayLists.
    This part is ok.
    Now the second part of the question is:
    What would happen if two concurrent threads try and remove the third object
    of such a collection?
    I don't know what to answer. I could tell that if the vector or arraylist is smaller than 3 il will return an ArrayOutOfBoundException but what happen if they are longer?
    Thank you very much.

    RaptorKiller wrote:
    Hello,
    I have a java test to give back tomorrow and I'm stuck on this question, could you help me please.
    Question: What is the difference between java.util.Vectorand java.util.ArrayList?
    I read everywhere that: The main difference between Vectors and ArrayLists is that Vectors are synchronized so any method that touches the Vector&#146;s content is thread safe ...hm. hmmm...
    I wouldn't say anything about Vector or its methods being thread safe.
    Thing is, [Vector javadoc|http://java.sun.com/javase/6/docs/api/java/util/Vector.html|javadoc] does not state anything like that.
    Rather opposite, javadoc says Vector hates concurrent modification just like any other non-concurrent collection: +"...The Iterators returned by Vector's iterator and listIterator methods are fail-fast: if the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException... Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification..."+
    This part is ok.I don't think this part is OK. I would stick with wording given in javadoc: +"Unlike the new collection implementations, Vector is synchronized"+ // synchronized does not necessarily mean thread safe, and Vector is the case proving that

  • Removing XML elements

    Hi all!
    I have a problem about an xml. I have to eliminate redundancy
    So from this xml:
    <xml1>
    <Property>
    <Parameters1>
    <Param>
    <name>A</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    <Param>
    <name>B</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    <Param>
    <name>C</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    </Parameters1>
    <Parameters2>
    <Param>
    <name>A</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    <Param>
    <name>C</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    <Param>
    <name>D</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    </Parameters2>
    </Property>
    </xml1>
    I want to obtain this xml:
    <xml2>
    <Property>
    <Parameters1>
    <Param>
    <name>A</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    <Param>
    <name>B</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    <Param>
    <name>C</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    </Parameters1>
    <Parameters2>
    <!--Parameters A and C are missing-->
    <Param>
    <name>D</name>
    <prop></prop> <!--this doesn't matter-->
    </Param>
    </Parameters2>
    </Property>
    </xml2>
    There are just parameters without repeting.
    My code until now is:
    private String numeParam;
    private Vector elParam = new Vector();
    for (int i=0;i<rootlist2.getLength();i++)
    Element element2 = (Element)rootlist2.item(i); // rootlist is my doc xml
    if (element2.getLocalName()==Property)
    NodeList childrenName2 = element2.getChildNodes();
    for (j=0;j<childrenName2.getLength();j++)
    Element elemm = (Element)childrenName2.item(j);
    if ((elemm.getLocalName() == "Parameters1")||(elemm.getLocalName() == "Parameters2"))
    NodeList param = elemm.getChildNodes();
    for(int y=0;y<param.getLength();y++)
    bn=true;
    bas=true;
    Element childInProperty2 = (Element)param.item(m2); // acesta e de sters
    if (childInProperty2.getLocalName() == Param)
    NodeList tlist =childInProperty2.getChildNodes();
    for (int y = 0;y<tlist.length();y++)
    Element childInPUParam2 = (Element)tlist.item(y);
    if (childInPUParam2.getLocalName()== "name")
    numeParam = childInPUParam2.getTextContent();
    bas=false;
    if (bas==false)
    if (!elParam.contains(numeParam))
    elParam.addElement(numeParam);
    if (elParam.contains(numeParam))
    bn=false;
    break;
    } end if
    } // end for
    if (bn==false)
    ba = false;
    if (bn==false)
    System.out.println("C");
    ba = false;
    elParam.clear();
    this is working I a kind of way, but this remove some elements that is not god. I wonder... Is like elParam contains some strings but, after me is imposible.
    Thanks all

    Why don't you use XPath? Anyway.
    -> Get a List of the documents Node
    -> Get a List of all children
    You have to check each Node:
    -> if the node is not null
    -> if the node's name is not null
    -> if the node's content is not null
    -> if the node's name is equals (<name>)
    If the Node-Element is found, store it in a Collection (the reference of the node object).
    Later you could iterate the collection and remove all Nodes from the Document.
    Afterwards you can transfer the document to a xml file.
    btw: if you use XPath you have to be sure to use at least Java 1.5
    Regards,
    Florian

  • WebDynpro Java: how to remove blank element from Table and Dropdown.

    Hi  Folks
    In a webdynpro application,
    I created a table and witten the below code to populate the table
         IPrivateDummyView.IFirst_TableElement First_Table_Element = null;
         First_Table_Element = wdContext.nodeFirst_Table().createFirst_TableElement();
         First_Table_Element.setF_Value("One");
         wdContext.nodeFirst_Table().addElement(First_Table_Element);
         First_Table_Element = wdContext.nodeFirst_Table().createFirst_TableElement();
         First_Table_Element.setF_Value("2");
         wdContext.nodeFirst_Table().addElement(First_Table_Element);
    As per the code, i got 2 row in the table.
    But , i have one Empty row on top of the table ,  how to get ride of this.
    i find the same problem happening with dropdown too, where i used DDBI, i populated a the content as mention, but i initial 2 row as blank and then i have my own elements ,as per my code.

    >
    > how to remove blank element from Table and Dropdown
    >
    Change selection property of related node to from 0..1 to 1..1 (mandatory)
    Re: DropdownByIndex and empty line (Thread: DropdownByIndex and empty line )
    Re: Can the empty selection be removed from element dropdownbykey(Thread: Can the empty selection be removed from element dropdownbykey )
    Edited by: Anagha Jawalekar on Nov 18, 2008 10:28 PM

  • Looping Over the Collection elements in the BPEL

    Hi Everybody,
    Note:It appears this thread long paragraph but those are schems structures only.I am giving them to give full depth of my req.
    1) First requirement :I have requirement wherein I have to retrieve the Data from Database adapter and modify it according to my requirements like below.
    1) Input data from Database Adapter example: (Initial Schema)
    <select_arrid_collection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/Select_Arrid">
    <select_arrid>
    <arr_id>arr1</arr_id>
    </select_arrid>
    <select_arrid>
    <arr_id>arr2</arr_id>
    </select_arrid>
    <select_arrid>
    <arr_id>arr1</arr_id>
    </select_arrid>
    <select_arrid>
    <arr_id>arr2</arr_id>
    </select_arrid>
    </select_arrid_collection>
    2) I am modifying to get the collection objects based on element same arr_id(If it is arr1,I have to get the all the elements related arr1 into one of the collection Object that is select_arrid_collection.Likewise for any arr_id ,it has to group them into a select_arrid_collection element) like below:
    Modified schema:
    <root xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/Select_Arrid">
    <select_arrid_collection>
    <select_arrid>
    <arr_id>arr1</arr_id>
    </select_arrid>
    <select_arrid>
    <arr_id>arr1</arr_id>
    </select_arrid>
    </select_arrid_collection>
    <select_arrid_collection>
    <select_arrid>
    <arr_id>arr2</arr_id>
    </select_arrid>
    <select_arrid>
    <arr_id>arr2</arr_id>
    </select_arrid>
    </select_arrid_collection>
    </root>
    Note: root element is added in the schema that is why this modified xml has different namespace
    I am using below xsl file to get the above schema to get the solution for first requirement:
    <xsl:stylesheet version="2.0" xmlns:ns1="http://www.example.org" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <ns1:root>
    <xsl:for-each-group select="*/ns1:Select_Arrid" group-by="ns1:Arr_id">
    <xsl:sort select="current-grouping-key()">
    <ns1:select_arrid_collection>
    <xsl:copy-of select="current-group()">
    <xsl:apply-templates/>
    </xsl:copy-of>
    </ns1:select_arrid_collection>
    </xsl:sort>
    </xsl:for-each-group>
    </ns1:root>
    </xsl:template>
    </xsl:stylesheet>
    2) Second requirement:
    After getting the multiple collection elements(select_arrid_collection),I want to loop through each select_arrid_collection element and map the elements in that to another service schema.
    I have created the xsd like above required modified schema and assign it to a variable(element type) which takes same modified schema so that I can have a variable on which I want to apply while activity.
    But I want to have the idea how to loop through the multiple collection elements(select_arrid_collection) and map the elements of each select_arrid_collection to a input variable of a service.
    My problem is I have to get each select_arrid_collection element in the schema where root element is 'root'.I am not able to trace how to get the no of select_arrid_collection elements so that I can loop through in the transofrm activity.
    Can anybody help me put in this?
    Edited by: 899283 on Jan 9, 2013 1:48 AM
    Edited by: 899283 on Jan 9, 2013 1:52 AM
    Edited by: 899283 on Jan 9, 2013 1:53 AM
    Edited by: 899283 on Jan 9, 2013 2:02 AM

    Can you please let us know if there are some helpful/correct answers in your previous questions and follow the forum etiquette? https://forums.oracle.com/forums/ann.jspa?annID=893
    Where Can I create Staging table in SOA server?
    regarding sending response at a time to a WSDL in BPEL
    Do we need nodemanager for SOA server installation?
    I want to set the time for polling of  DB Adapter

  • How do I remove Photoshop Elements help files?

    Greetings,
    I removed Photoshop Elements 9, but the help files are still in Adobe Community Help 3.5.0.23. How do I remove the PSE9 files from Community Help?
    I'm using Windows 7 Home Premium SP1 64-bit.
    Thanks,
    Shane.

    Thanks. Tried the FAQ before posting.  Perhaps you are better at wording a query; my attempts were unsuccessful. Am using the 30 day trial to see if I wish to purchase PE as the Oranizer function is my primary interest. Still would greatly appreciate some guideance so that I might proceed with importing contents of my HD as part my trial.
    Regards,
    OMPS

  • Removing an element with JDOM

    Using JDOM, does anyone know of a way to remove an element? Thanks,
    chris

    Found the answer. removeChild() gets the job done.

  • I am not able to remove an element of my side bar of the finder

    I am not able to remove an element of my side bar of the finder

    Try holding down the COMMAND key while dragging the element to the desktop.

  • Remove blank element in array

    need help how to remove empty elements in an array?

    Hi jeyanthi,
    if you want to delete somthing from a txt file, you have also first to read the data, remove the part you want and to write the new data into the file. So i think you can do it with the array version. For example something like this:
    Mike
    Message Edited by MikeS81 on 06-09-2008 09:32 AM
    Attachments:
    Unbenannt1.PNG ‏6 KB

  • How to manually remove Photoshop Elements 4.0 from Windows

    My uninstaller for Photoshop Elements 4.0 in Add or Remove programs fails with the message - "This action is only valid for products that are currently installed." The program folder still resides on my harddrive. The program itself neither runs nor will it allow me to delete the program files' Photoshop Elements 4.0 folder that contains the executable and dll files from my harddrive. I need a manual uninstall proceedure.

    Have you got the disc? If so, you might try installing it again then an uninstall.
    Failing that...
    Here's the Adobe tech doc on removing Photoshop Elements 5. I would assume it would be the same procedure.
    http://kb2.adobe.com/cps/333/333201.html

  • I removed Photoshop Elements 9 and 10 from my laptop. It also removed parts of my version 12. I am not able to re-install verion 12. The install program keeps wanting to un-install version 12

    I was cleaning up the programs on my hard drive and removed Photoshop Elements 9 and 10. I used Revo Uninstaller Pro to remove all the left over files and registry entries. Revo also removed parts of my version 12. I re-downloaded the demo version again as I already have the serial number. When I run the install program files my only choice is to remove version 12 and I'm not able to install

    Try this,
    Run the cleaner tool. clean the product(if you see).
    Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
    Then Rename/delete all the Adobe folders.
    The locations are: 64 bit computer.
    C:\Program Files (x86)\Common Files\Adobe.
    32 bit computer.
    C:\Program Files \Common Files\Adobe.
    C:\ProgramData\Adobe.
    You also have Adobe folders in :
    C:\Users\[user name]\AppData\Local\Adobe
    C:\Users\[user name]\AppData\Locallow\Adobe
    C:\Users\[user name]\AppData\Roaming\Adobe\OOBE
    Then Re-install the product.

  • How to remove photoshop elements 3 from being the default program to open photos

    how to remove photoshop elements 3 from being the default program to open photos in iMac 10.6.8; want to use Preview 5.0.3 as before. Somehow I clicked an "ok" to a question asking if I wanted photoshop e 3 to be the default program (NOOOO - too slow, too cumbersome just for viewing pix) What was I thinking????

    This might help just found googling http://www.bittbox.com/os-x/how-to-set-the-default-program-to-open-a-certain-type-of-file- in-mac-os-x
    Try once please.
    Thanks,
    Garry

  • I have photoshop elements 13 and want to remove photoshop elements 10 first.  When I try to remove 10 I get error 1316 , specified account already exests and will not remove. I have windows 7

    I have photoshop elements 13 and want to remove photoshop elements 10 first.  When I try to remove 10 I get error 1316 , specified account already exests and will not remove. I have windows 7

    Exit Code: 6, Exit Code: 7 Installation Errors - http://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
    Troubleshoot with install logs | CS5, CS5.5, CS6 - http://helpx.adobe.com/creative-suite/kb/troubleshoot-install-logs-cs5-cs5.html for information on how to review your installation logs

Maybe you are looking for