Sync on iterating thru a ConcurrentHashMap?

i've read that synchronizing on collections while iterating thru them is tricky.
i "think" one should normally do this:
Map<Connection, Boolean> connPool = new HashMap<Connection, Boolean>();
Set<Connection> connSet = map.keySet();
Iterator it = connSet.iterator();
syncrhonize(it) {  // correct object to synchronize on
  while(it.hasNext()) {
}as opposed to doing this:
Map<Connection, Boolean> connPool = new HashMap<Connection, Boolean>();
Set<Connection> connSet = map.keySet();
Iterator it = connSet.iterator();
syncrhonize(connSet) {  // <-- _WRONG_ object to synchronize on
  while(it.hasNext()) {
}now, what if i am using
java.util.concurrent.ConcurrentHashMap
i read the API:
+....... However, iterators are designed to be used by only one thread at a time. ......+
my interpretation of this is that
if i iterate on a ConcurrentHashMap i would still need to synchronize on the Iterator (just like in a standard HashMap ), right?

the situation is:
i have many threads that analyze data and they retrieve from a database.
opening a java.sql.Connection is extremely slow, so i use a Connection pool:
ConcurrentHashMap<Connection, Boolean> connPool;
the Boolean value is "true" if the Connection is not being used by another thread.
for example, i might have 15 data analysis Threads and 5 Connections in the connectionPool.
when a Thread needs to query the database, it asks for an idle Connection.
so, i Iterate over the keySet() of the connPool Map looking for a "true" value. if i iterate thru the whole Map and do not find an
idle Connection, i add a new Connection. (so far, there is no need for synchronizing).
but then what i do to increase performance, because opening a new Connection is so slow, i start a background thread to create and then add a new Connection and the iteration continues in parallel. (note: an already open Connection might be released before a new Connection is created)
once the background thread opens a new Connection, it will connPool.put(dbConn, Boolean.TRUE); while the iteration over connPool is continuing in the primary Connection pool object.

Similar Messages

  • Recently, when I hook up my iPhone to Sync, it goes thru and when it finishes I get the same message......The iPhone "......" cannot be syned. An unknown error occurred (13019).  What am I doing wrong?

    Recently, when I hook up my iPhone to Sync, it goes thru and when it finishes I get the same message......The iPhone "......" cannot be syned. An unknown error occurred (13019).  What am I doing wrong?

    I dug a little deeper and found this:
    It is the Voice Memos in the Playlist check Box. Uncheck it and re-sync.
    It helped this time on my iTouch and my iPhone!  At least this time.

  • My Ipad Air wont sync or charge thru laptop

    My ipad air 7.0.4 wont connect to itunes( the latest one) or charge thru laptop

    Could be a bad cable. Make sure the connector is fully seated.
    The laptop doesn't provide enough USB power to charge. Use the charger that came with your iPad.
    iPad not appearing in iTunes
    http://www.apple.com/support/ipad/assistant/itunes/
    iOS: Device not recognized in iTunes for Mac OS X
    http://support.apple.com/kb/TS1591
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    iTunes for Windows: Device Sync Tests
    http://support.apple.com/kb/HT4235
    IOS: Syncing with iTunes
    http://support.apple.com/kb/HT1386
    Apple - Support - iPad - Syncing
    http://www.apple.com/support/ipad/syncing/
    iTunes 10.5 and later: Troubleshooting iTunes Wi-Fi Syncing
    http://support.apple.com/kb/ts4062
     Cheers, Tom

  • My "notes" on iPad will not sync with iPhone thru iCloud. What gives?

    My "notes" on iphone and iPad will not sync thru iCloud. I am sure it is user error...but I can not figure it out.

    It reads like this is a problem on the iOS side. On your iPhone or iPad launch the notes app, in the top left corner tap the button until you are on the Accounts page and see if iCloud is an option. If it is select that option and new notes will push to your Mac. If its not close the Notes app and go to Settings > iCloud > Notes > Toggle On. The option will now be in the notes app as described above. Side note: You may be asked to set up an iCloud email if you haven't already. Hope that helps.

  • I've upgraded from outlook 2003 to 2010. My iphone 4 wont sync - but goes thru the motions???

    I can't get my iphone 4 to sync with my new office 2010/windows 7 system. It goes thru the motions but doesn't transfer the data??

    Hi,
    What account do you have in Outlook 2010? Exchange, IMAP or POP?
    Based on your description, the imported emails can't be searched, which in my opinion is because these new emails have not been actually indexed. I suggest you rebuild the index to check the result.
    In Control Panel, Search "Indexing Options" and open it, make sure Outlook is included in the Locations list, and click "Advanced" button. Click "Rebuild" button, when there's a prompt pop up, click "OK".
    It may take a long time to complete, I suggest you do this at night after you finish work.
    Regards,
    Melon Chen
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Syncing Purchased Ringtones thru work comp

    I have two computers my phone regularly gets used on: my home (my main computer) and my work computer.
    Since I no longer have internet on my home computer, I have been downloading apps and putting them on my phone at work. They sync without any problem. I downloaded a song and a ringtone today and it mentions my phone is synced to another library and asks if I want to erase it and sync with my work library.
    questions:
    1. If I just select sync ringtones will it still erase my music?
    2. Why can't I sync with my work computer if the phone is the same and my log-in is the same?
    3. Will I be able to access my purchased ringtone on another computer ever?
    4. How can I get my purchased ringtone on my phone without losing everything?

    I have a problem ~ I have an iPhone 3G and I use my Macbook to sync the applications I purchased from iTunes using this computer. My Macbook crashed and I had to replace my HD with a new one. So all my applications in that computer are now gone (cause hahaha, I didn't back it up) Anyway, I also have an iMac in that computer I have my music and videos that I sync my iPod video to. (I have a Time Machine to back up my data in that computer) Now this is my problem:
    1. Can I download the same applications I bought using the same account into my iMac? I hope I don't get charged for them cause I've spent about US$300 buying program for my language lessons there.
    2. Will my address book get erased if I sync my iPhone to my iMac?
    I am asking this because I've tried syncing my iPhone to my Macbook it only gets the photos in my iPhone to go to iPhoto but it doesn't want to appear in my iTunes. And finally, I just want to do everything in my iMac cause I have a back up there in case something happens again. In other words, I am thinking that if I can download the applications I bought there at no charge and if my address book in my iPhone won't get deleted. I am considering reformatting my entire iPhone since I want to download the application I bought in my iMac anyway. If not, I won't be able to buy new applications from iTunes and just update what I have in my iPhone using wi-fi and I don't want that. I want the option to install/uninstall any application I want depending on my mood. Oh I forgot to mention that I have the same account in my iMac but it only recognizes my iPod video. It also doesn't want to read my iPhone. But I get a warning that I already have registered that user name in 3 computers. One is my iMac and two from my Macbook meaning the one that crashed and the same computer with a new hard drive.
    To summarize, I just want to know if I can DL the same applications without being charged and if my address book won't get lost if I sync my iPhone to the iMac (hopefully, my iMac gets to read my iPhone). Thanks in advance. I hope the way I shared my story isn't so confusing.

  • Iterating thru an array list and displaying it on the table.

    Hi All,
    I have done table binding.
    Say if I have a list of values(pojo's) in the request scope. I need to iterate thru the list and display the attributes enclosed inside the pojo on a JSF page.
    How do I achieve it?
    Thanks
    - Gana.

    Hi,
    it depends on what you mean by "I have done the table binding". A Pojo can be used as the base for a data control, which then can be bound to a table through this (using ADF).
    If you want to copy values to a table, you can access the binding container in a managed bean (you didn't tell the technology you use so i assume JSF). Check SRDemo on how to access the binding container in a managed bean (see SRMain for example)
    Frank

  • Network (not desktop) sync of calendar - thru whatever?

    OK. I joined this forum to ask this one question, which Apple should just post at the top in a sticky. I've googled and read and searched and looked at KBs and read many of the threads posted here. The information that I've found is not encouraging. I would like just one clear coherent response.
    Does Apple currently support network/push/active/online/wireless updating of calendar and contacts?
    If I cannot get a calendar that updates the calendar dynamically, at least every 15 to 20 minutes, without me plugging the phone into a cable, then I want the message to Apple to be CLEAR: I WILL NOT BUY THIS PHONE.
    SO...what's the answer?

    No you have to plug and sync your phone into Itunes to get update from your phone to your computer and your computer to your phone. Not like a Black Berry.
    You might be able to do this with a hacked phone, but it would no longer be covered by apple.
    As for telling apple you won't buy because of its limitation... ha ha ha they don't care much. you can go the the feedback page a give them a bit of your mind.

  • IWork docs on my iPad still won't sync to MBP thru the iCloud via MtLion.

    I have "sync to iCloud" enabled on both iPad and Mac Book Pro. docs from ipad are in my iCloud account. How do i make the MBP sync to this? This is why I bought Mt. Lion

    Calendar and contacts work fine.... they worked fine in Lion too

  • HT1386 sync 2 iphones thru itunes on the same macbook

    Hi
    How can I sync 2 iphones on the same macbook?

    Plug one in and sync it.
    Plug the other one in and sync it.

  • Photostream does not sync with computer thru iCloud

    I have an iPhone 4S.  I use iCloud for calendars/contacts and photostream.  For some unknown reason photostream sync does not work to my computer.  It does sync to the iPad from the iPhone.  Software has been updated on iPhone and in iCloud control center.  I have deleted iCloud on computer and re-installed without any success.  I absolutely love taking the photo with the iPhone and having it transfer to the computer.  Any ideas .. would appreciate some help.  Plenty of battery on the iPhone and maybe 100 photos total.  Deleted all the old photos didn't help either.  I am at a loss. 
    I hate re-installating the iCloud control center beause it messes up the sync on calendars.  Yes, I use a PC.  (horrors).

    syncing is via iCloud for PC, not via iTunes, so it should be immaterial whether iTunes is latest version.

  • Sync iPod Touch4 thru  USB

    I want to use my iPod Touch4 for business but my company doesn't support Wi-Fi. Is there any way to sync Word, Excell and Outlook through the USB port to a third party app such as DocsToGo?

    The description says that DocToGo uses File Sharing. Therefore you can sync documents to the app via iTunes using USB. However, you work computer must have iTunes installed and must be your main syncing computer. You can sync music from your home computer by manually managing music on your iPod.

  • I've always sync my iPad thru my mac now the sync is cancelled on its own

    trying to sinc some photos from my mac to my ipad and it is cancelling the sinc is there a new problem

    No, you can't. The purpose is to have a backup copy of them and provide another way of putting them on other iOS devices.
    (80028)

  • HT1296 I am trying to sync my ipod to my computer thru itunes, I have already successfully synced my ipad, but keep getting stuck on the sync for the ipod it identifies, the device appears to be syncing but doesn't show up my new music or my new playlist?

    I am trying to sync my i-pod to my computer thru itunes.  I successfully synced my Ipad thru the computer, but am trying to do the same with the Ipod.  The device shows up on my computer and appears to be syncing, but nothing changes.  I have tried dragging the new music to the device, but a symbol appears with a slash thru the middle, as if denying access, any suggestions what to try next.  I have synced on this Ipod succesfully in the past, Suggestions?

    To drag and drop you have to use the Manual Method. That method is included here:
    iTunes: Syncing media content to iOS devices and iPod
    Was the iPod set up by wifi or setup or synced to another computer/iTunes library?

  • Ipod won't sync."unknown error (-69)"

    I've had months of no problems with Ipod classic 80g. I purchased some more music, one song of about 20 synced onto my ipod. Then I got a message from itunes saying: "Attempting to copy to the disk "MOM'S IPOD" failed. An unknown error occurred (-69)" I've spent hours trying different options, my recent purchases are on my library, but only the first song is on my ipod!! This happened right after the last update of i-tunes. Is there a bug with that or what?

    Thank You!!! I don't know WHY file (Eric Clapton-Pilgrim CD)was bad when I've had it in there for a few months. But that's what it kept stopping on when tring to sync. So I deleated it and sync finally ran thru w/o a ERROR code. I think I will try to reinstall it later and see what happens. Thanks again for responding. it is easy to get lost in all of this info, I had't found that page.

Maybe you are looking for

  • Print images in a pdf doc

    Hi, I'm inserting a gif image (logo from a png file) into a word doc and converting it to pdf. When I print the pdf file the logo appears very blurry (low quality). What am I doing wrong? Any help is appreciated! Thanks, Susannah

  • No FireWire ports were found on MacBook Pro 15.4" running Mac OS 10.6.4

    Hello all, I recently bought a Mac Book Pro with Intel Core i7 and 2,66 GHz with a 4 GB RAM. The system is good, until I connected my external hard drive from Mac Way that connects to the laptop through a Firewire 800. The HD mounts well with a USB b

  • Issue at billing

    A delivery has  two different origins on the same item for which our system is supposed to create two different delivery notes. We have 100PCs of Item soap from Canada and 200 PCs of bottles from US.  The real issue is in the invoice it is showing 30

  • BPM payload value reading problem

    Hi all, In a bpm scenario, I have a switch that checks an element's attribute and another that checks an element's value.  In the former case, the TRUE branch gets executed when the condition is satisfied.  However, in the latter the condition is NEV

  • Keep getting a request for password "for the CalDAV account for my email account when I log in my iPhone password. ????

    I keep getting a request "for the CalDAv account" when I log in using my iPhone password on my iPhone.  Just started happening.   ????