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?

Similar Messages

  • 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

  • [svn:osmf:] 16975: Fix bug FM-964, add media factory item for RTMFP multicast and remove the item from OSMFPlayer

    Revision: 16975
    Revision: 16975
    Author:   [email protected]
    Date:     2010-07-19 15:20:00 -0700 (Mon, 19 Jul 2010)
    Log Message:
    Fix bug FM-964, add media factory item for RTMFP multicast and remove the item from OSMFPlayer
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FM-964
    Modified Paths:
        osmf/trunk/apps/samples/framework/OSMFPlayer/src/OSMFPlayer.as
        osmf/trunk/framework/OSMF/org/osmf/media/DefaultMediaFactory.as

    Welcome guy -
    Unless you are using Spry menus as a learning experience, you should move forward to a menus system that will display properly on the millions of portable devices that won't work with Spry which was deprecated 2 years ago.
    Many are using JQuery menus or pure HTML/CSS menus.
    If you wish to continue your Spry for learning experience, we'll be glad to assist; please let us know.
    By the way, your submenus are not showing because you need to add the red value to this rule in your vertical CSS
    ul.MenuBarVertical ul.MenuBarSubmenuVisible{
        width: 220px;
        left: 180px;

  • 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.

  • Apple, why did you change my Keyboard and remove the enter key?

    Hi all,
    I had my new black MacBook delivered just before Christmas. The keyboard has changed from my previous Black MacBook (the one a colleague poured wine over and killed... grrr).
    Apple have changed the look of the command key and removed the Apple logo (very sad), but more frustratingly have replaced the 'enter' key with another 'option' key.
    I found the 'enter' key really useful, especially for pull down menu and really miss having one.
    Does anyone know if there is a way to assign the new 'option' key to be an 'enter' key?
    Cheers
    Scott.

    I just received a new(refub) MacBook 2.2GHz today and was very disappointed to find the enter key missing. After selling my G4 PowerBook six months ago, I was so looking forward to having the convenience of being able to slap the enter key for dialog boxes with and submitting forms without having to move my hand from the trackpad. I hope that someone will come up with a way to replace the functionality of the missing enter key.
    Which brings me to my next point- There has been a big oversight in the implementation of the MacBook's replacement of the Enter Key, which is to use the FN+Return keys. It seems that when using the FN key with the Return key, the system will ignore the Command key being invoked. I discovered this very quickly. Anyone who uses Apple Remote Desktop knows that in order to send a Unix command to a remote machine, you type the command in the 'send UNIX command' window, then hit Command+Enter to send the command. Return produces a carriage return, FN+Return does nothing, and FNCommandReturn does nothing. The only current work around is to use the track pad to the "Send" button and click, which really slows things down.

  • My iPad is disabled and won't connect to iTunes on any computer; I went to my iCloud and removed the iPad so it will erase all data when the iPad is connected to the internet (the original problem was a restrictions passcode we forgot)

    Here is the order of what I did to my iPad:
    1.  A restrictions passcode was put on and we couldn't remember it.  Despite numerous attempts at righting this, I couldn't. The iPad would not sync with any iTunes on any computer, Mac or PC.
    2.  I put a, 'use passcode after one minute' passcode on it and deliberately put in 10 wrong passcodes so it would disable the iPad.  Now it still will not connect to any iTunes.
    3.  I connected to my iCloud account and removed the iPad from the cloud; it says it will erase all iPad data when it connects to the internet.  I am fine with that, I need to know what to do now, though. iPad says, 'Connect to iTunes,' but it won't.  Please help this amateur of all amateurs!!

    See iPhone DFU mode explained, and how to enter DFU mode.

  • How do I find bad music files?  I have thousands of files, but some are bad.  When I try to load them into iTunes, it just spins.  I need a routine to identify and remove the bad files.  Any ideas?

    How do I find bad music files?  I have thousands of files, but some are bad.  When I try to load them into iTunes, it just spins.  I need a routine to identify and remove the bad files.  Any ideas?

    Hi ajoddo20,
    Welcome to the Apple Support Communities!
    You can use Home Sharing to import music and other media from one computer to another. Please use the instructions and information located in the attached article for information on how to complete the process. 
    iTunes 11 for Mac: Use Home Sharing to import items from another iTunes library
    Cheers,
    Joe 

  • How do I change platform for downloading and installing Photoshop Elements from Windows to Mac?

    How do I change platform for downloading and installing Photoshop Elements from Windows to Mac?

    As long as your license supports both platforms you should only have to download the Mac version and install/activate using your serial number.  If you need help finding a link to download the file, please indicate the PSE version you need.

  • Read two CSV files and remove the duplicate values within them.

    Hi,
    I want to read two CSV files(which contains more than 100 rows and 100 columns) and remove the duplicate values within that two files and merge all the unique values and display it as a single file.
    Can anyone help me out.
    Thanks in advance.

    kirthi wrote:
    Can you help me....Yeah, I've just finished... Here's a skeleton of my solution.
    The first thing I think you should do is write a line-parser which splits your input data up into fields, and test it.
    Then fill out the below parse method, and test it with that debugPrint method.
    Then go to work on the print method.
    I can help a bit along the way, but if you want to do this then you have to do it yourself. I'm not going to do it for you.
    Cheers. Keith.
    package forums.kirthi;
    import java.util.*;
    import java.io.PrintStream;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import krc.utilz.io.ParseException;
    import krc.utilz.io.Filez.LineParser;
    import krc.utilz.io.Filez.CsvLineParser;
    public class DistinctColumnValuesFromCsvFiles
      public static void main(String[] args) {
        if (args.length==0) args = new String[] {"input1.csv", "input2.csv"};
        try {
          // data is a Map of ColumnNames to Sets-Of-Values
          Map<String,Set<String>> data = new HashMap<String,Set<String>>();
          // add the contents of each file to the data
          for ( String filename : args ) {
            data.putAll(parse(filename));
          // print the data to output.csv
          print(data);
        } catch (Exception e) {
          e.printStackTrace();
      private static Map<String,Set<String>> parse(String filename) throws IOException, ParseException {
        BufferedReader reader = null;
        try {
          reader = new BufferedReader(new FileReader(filename));
          CsvLineParser.squeeze = true; // field.trim().replaceAll("\\s+"," ")
          LineParser<String[]> parser = new CsvLineParser();
          int lineNumber = 1;
          // 1. read the column names (first line of file) into a List
          // 2. read the column values (subsequent lines of file) into a List of Set's of String's
          // 3. build a Map of columnName --> columnValues and return it
        } finally {
          if(reader!=null)reader.close();
      private static void debugPrint(Map<String,Set<String>> data) {
        for ( Map.Entry<String,Set<String>> entry : data.entrySet() ) {
          System.out.println("DEBUG: "+entry.getKey()+" "+Arrays.toString(entry.getValue().toArray(new String[0])));
      private static void print(Map<String,Set<String>> data) {
        // 1. get the column names from the table.
        // 2. create a List of List's of String's called matrix; logically [COL][ROW]
        // 3. print the column names and add the List<String> for this col to the matrix
        // 4. print the matrix by inerating columns and then rows
    }

  • How can I find and remove duplicate photos from my computer?

    How can I find and remove duplicate photos from my computer?

    Terence,
    Yes, the duplicates appear in the iPhoto window. I have folders with same name occuring two or even three times sometimes with exactly the same set of photos (ie photos with the same ID) and sometimes with a limited set of photos. Other  folders appear only once.
    I normally take my MacBook with me if I'm shooting a lot of photos, such as on holiday, and then want to transfer them to my iMac when i get home. Other times I transfer the camera's memory stick directly to my iMac.
    I have great difficulty transferring the photos from my MacBook to my iMac. I don't want to store my photos on my iDisk due to the length of time it takes to upload them.
    Thanks again.
    Simon

  • Extend the EPM install to a new EOI and remove the old EOI's (server decommissioning). EPM version 11.1.2.1 and having essbase and planning; I understand removing EOI's is not as simple as 11.1.2.3 but any suggestion/steps would be of great help.

    Extend the EPM install to a new EOI and remove the old EOI's (server decommissioning). EPM version 11.1.2.1 and having essbase and planning; I understand removing EOI's is not as simple as 11.1.2.3 but any suggestion/steps would be of great help....

    Next time try to create a topic that is not the question.
    There was no option to remove epm instances in 11.1.2.1, basically the cloest you get is uninstalling the products on the server and hope that some of the info is removed from the epm registry
    Cheers
    John

  • Hi, How to export my Photoshop Elements 8 and Premiere 8 Elements from my old PC to my new PC

    Hi, How to export my Photoshop Elements 8 and Premiere 8 Elements from my old PC to my new one - both are Windows 7???

    Hi Jeff,
    Thanks for reply.
    I want to transfer/export/bring over images and videos to my new PC.
    I have one licence (and disc) in my old PC for Photoshop Elements 8 and Premiere Elements 8.
    Separately I have one unused licence (disk) for  Photoshop Elements 10 and Premiere Elements 10.
    I also then need to understand the smartest and easiest approach to:
    Either I export software 8.0 and images and videos from old to  new PC
    - Or
    I install version 10 on the new PC and then  transfer/export/bring over images and videos to my new PC.
    Great if you are able to guide me in this.
    Regards,
    Per S

  • My new iPhone 4S has hearing problem.speaker and headphone works very good.However using handset to make and receive calls I cannot hear anything?I did restore the phone and removed the plastic.Is there any solution to this problem please?

    I am having heraing problem with iPhone 4S.Speaker and headphone works well.No echo.When I use handset to receive or make calls,I can't hear anything?I restore the phone and removed the plastic as well.Is there anyway to fix this problem?

    I personally haven't experienced much of the "reverberation/feedback" when using a headset on the i4S...
    Yes, I have near-perfect hearing too (for scope, squeaky brakes hurt my ears) I come from many conversations on many phones and types and first off, CDMA technology is great for coverage, terrible for voice quality. HD Voice in Europe made for some of the best phone conversations I've ever had.
    Back on track, feedback is most noticable (similar to the landline phone) when using the iPhone without a headset, but for me it's not an absolute criticality mainly because I use VoIP apps alot, so maybe it has desensitized me some over the past year.
    But whenever I'm on a call, and the other person has me on speakerphone, I have alot of trouble talking because of the feedback loop caused. So the less of my voice I hear the better I can talk.
    Have you tried a bluetooth headset yet?

  • How can i uninstall Windows 7 and remove the partition?

    how can i uninstall Windows 7 and remove the partition?  white unibody late 2009.  i cannot seem to find bootcamp either :/

    Open the Boot Camp Assistant in the /Applications/Utilities/ folder and use it to restore the drive to a single partition setup. If it's not there, use Pacifist to extract it from your install DVD and run the combo updater for your OS version.
    (79308)

  • X120e 0596 screen wont wake up after sleep mode until unplug it and remove the battery

    I recently purchased a Thinkpad X120e (0596) and am genneraly very happy with it however when it goes to sleep the screen does not wake up when the laptop does. when i wake it up i hear the fan spin up but the the screen remans powered off. ive tried waiting several minutes and it still doesnt wake up, ive also tried holding the power button for several (more than 5 ) seconds to force it to power off fully then start it again and the screen still doesnt wake up. the only way i can get it to work again is to make sure to unplug it and remove the battery for several seconds then i can get it to boot with the normaly expected complaints from windows after an abnormal shutdown.
    I have the latest updates from lenovo and microsoft installed including the latest firmware. I like the laptop so i would rather report the problem and provide any information neccisary to find a resolution than have to return it. Ive seen this problem with other laptops before and know its probably a  bug in the firmware thats not waking up the GPU is ther any tool i can use to provide the debuging info or any more direct way for me to report the bug I tried calling customer support and they told me they told me my only option was to return it and they could not report or record the issue.

    Same issue here, confirmed many times in linux, will likely recur at some point now that I am on windows (8).  The event log from the HAL says "The platform firmware has corrupted memory across the previous system power transition. Please check for updated firmware for your system" even after successful suspends, so who knows what happens when it fails. Since it's video-related, the problem could as well be in AMD's driver (also hinting at this is the fact the system periodically freezes when the screen is simply turned off from being idle).
    Also worth noting is the fact suspend seemed to work just fine on my system with the factory BIOS (1.08), with the issue appearing only in newer ones (the oldest one still available for download is already affected, and I am running the latest one). There are also slight differences in the issue between the legacy and UEFI boot modes, but none of them mitigate it.

Maybe you are looking for