What does this code mean?

private static ThreadLocal serialNum = new ThreadLocal() {
         protected synchronized Object initialValue() {
             return new Integer(nextSerialNum++);
     };

That code appears to be cut from this sample code found in the LocalThread javadoc:public class SerialNum
    // The next serial number to be assigned
    private static int nextSerialNum = 0;
    private static ThreadLocal serialNum = new
        ThreadLocal()
            protected synchronized Object initialValue()
                return new Integer(nextSerialNum++);
    public static int get()
        return ((Integer) (serialNum.get())).intValue();
}The lines you're asking about declare a static ThreadLocal by the name of "serialNum". They assign to it an inline definition (extension) of LocalThread which specifies a custom initialValue() method. That initialValue() method is designed to get its value from the nextSerialNum variable (static, and incremented each time).
The neat thing that happens with the ThreadLocal instance is in the get() and set() methods. Here you see the get() method being called:return ((Integer) (serialNum.get())).intValue();That get method returns a different object for each thread which calls it. When a new thread comes into the get() method, the initialValue() method is called, creating for that thread a new serial number. When THAT thread calls get() again later, it is given that same serial number.
This one (static) instance of ThreadLocal can be accessed by any number of threads, but each thread will get()/set() a different variable, specific to that thread. This serial number implementation sets up a very simple counter for the Integer object the various threads will receive. When calling get(), the first thread will always receive an (int)0, the second thread will always receive an (int)1, the third an (int)2, and so on.

Similar Messages

  • I have just tried to sync my iphone. Error message saying it cannot be synced has popped up quoting error code (-50). I have just removed old iphone backups from itunes but was very careful to not delete the current one. What does this code mean?

    Hi there,
    I have just tried to sync my iphone.
    Worryingly an error message saying it cannot be synced has popped up quoting error code (-50)
    I have just removed old iphone backups from itunes but was very careful to not delete the current one
    What does this code mean?

    http://support.apple.com/kb/TS1583

  • Getting 8010 errors from iTunes when trying to download app updates.  What does this code mean and how do I fix this?

    I have a 2009 iMac running Yosemite.  I was having no problems at all until I had some router issues and since I resolved those connection problems, iTunes has been giving me these 8010 errors.  My internet connection is good because I can get email and surf the web.

    Hi there I've just installed CS4 Pro on Windows 7 64bit and got exactly the same result as you. Did you manage to find anything out, because the thing that bothered me was the limited functionality (what ever that is). Is it just a case of Windows 7 having a newer version of ActiveX already installed?

  • What does " this code must be redeemed in the Australian storefront " mean? And how can I fix it?

    What does " this code must be redeemed in the Australian storefront " mean? And can I fix it?

    All iTunes gifts and gift cards are country-specific, they can only be redeemed and used in their country of issue. Are you in Australia with an Australian billing address on your account ? If you are then try going to the bottom of the Featured tab in the App Store app on your iPad and tap on your account id, tap on 'View Apple ID' on the popup and log into your account, and then select the Country/Region section and select Australia.
    If you are not in Australia then you won't be able to use it.

  • I bought a used iphone 4 and it is locked. When I try to recover it shows code 1671. What does the code mean?

    How do I do factory reset on an iphone 4? I bought it used and it has a password and when I tried to reset the phone it shows error code 1671. What does that code mean? Thanks

    Hello tresacg,
    Thank you for using Apple Support Communities. 
    It sounds like the previous owner has enabled a password on it. The first thing you can try is in this article:
    Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support
    Regards,
    Jeff D. 

  • What does this message mean:  this apple ID has not yet been used in the iTunes store"? I cant connect using my iphone. But it works in iTunes on my laptop.

    what does this message mean:  this apple ID has not yet been used in the iTunes store"? I cant connect using my iphone. But it works in iTunes on my laptop.

    FAQ apple id http://support.apple.com/kb/HT5622?viewlocale=en_US
    http://support.apple.com/kb/HT1311

  • What does this message mean?  "ITunes has fetected an iPad in recovery mode.  You must restore this iPad before it can be used with ITunes".

    What does this message mean?  "itunes has detected an iPad in recovery mode.  You must restore this iPad before it can be used with ITnes."  How do I restore when every time I connect to my computer I get this message?

    Perhaps the information in this Apple support article will help:
    http://support.apple.com/kb/TS3694#error3004
    Regards.

  • What does this message mean Charging is not supported with this device?

    What does this message mean Charging is not supported with this device?

    You've gotten 2 good answers already, but there's a key assumption in both that you got the message when connecting the iPhone to some other device. If this is the case you can get an adapter in the Apple online store that will allow charging from older devices.
    If, however, this message appears when you are not connected to anything the problem is dirt or moisture in the dock connector at the bottom of the phone. Clean it with a dry toothbrush or air blast.

  • What does this message mean? : "The file name "DSC_0088.jpg" is offline or missing." ?

    What does this message mean? : "The file name "DSC_0088.jpg" is offline or missing."   I am in the process of importing photos from iPhoto (don't really know what I'm doing....) and when I look at one of the imported photos that message pops up.  I know what "DSC_0088.jpg" is.  I don't know what it means that the file is "missing".

    CASpyr,
    Thank you so much for your reply.  I have a couple of bigger issues that I am dealing with: too many photos on my laptop: 40,000! (Of course I have to throw away many of them, but that is time consuming). I have a MacBook Pro and have primarily used IPhoto. I have recently purchased 2 external drives and have transferred my photos to those, but I need a basic education about how photos are stored, copied, etc.  I have recently been told that iPhoto only shows and deals with jpegs, not RAW.  About 1/3 of my photos are RAW, so I purchased Lightroom, so I could do more with those RAW photos.  I have been told by my local Mac store that I need to delete most of my photos from iPhoto, because it's causing problems.  I am reluctant to do so until I am sure that all of the keywords, descriptions and editing I have done to these photos is not lost when deleted from iPhoto. I just watched a tutorial about importing to Lightroom and got out of it that I needed to copy photos from iPhoto to a file on my desktop and then copy to Lightroom.  I did that, it seemed to work.  Then (because of my storage/memory issues) I deleted the photos (just a few as an experiment) from that desktop file.  I'm guessing that is why Lightroom doesn't recognize the the photos.  It seems that (learned from another tutorial) that one uses "Add" , Lightroom is only connecting to the source of the photo, not  actually copying it to the program.  Sounds like I need to use the "Move" feature instead.  My ultimate goal is to store the photos on the 2 external drives and eliminate most of them from my lapop.  So my basic questions have to do with what data (metadata??) is copied from iPhoto to an external drive (RAW???) and what isn't copied. Basic understanding issues,obviously….  I hope this isn't too much to ask.  If you can recommend a book or resource that can explain those basic issues to me I'd appreciate it.  I just got back from a trip and I can't download my new photos until I manage the rest!
    Thanks,
    Nancy

  • What does this message mean - The operation can't be completed because the item "12b" is in use.

    The operation can’t be completed because the item “12b” is in use.  What does this message mean.  It appeared as I was attempting to clear my time machine backup?

    Reboot your machine make sure Aperture doesn't start (as Lion is liable to do) and try it.

  • What does this message mean baring in mind we don't know who 'Lareib' is?: ''Lareibs phone' is now using (my number) for iMessage'

    What does this message mean baring in mind we don't know who 'Lareib' is?: ''Lareibs phone' is now using (my number) for iMessage'

    How would we users in this forum also know who Lareib is?
    It means what is stated, that person is now using your number for imessage.

  • What does this message mean? "Warning: SUID file "System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAg ent" has been modified and will not be repaired"

    What does this message mean? "Warning: SUID file "System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAg ent" has been modified and will not be repaired"  I get this when I try to repair permissions in disk utility.

    It's an innocuous error you can ignore. It was introduced with previous updates for ARD and/or Java before Lion. These are messages, not errors. They will cause no harm, and they will be repeated each time you repair permissions.

  • What does this message mean: "power pc applications are no longer supported"?

    What does this message mean: you can not start because power pc applications are no longer supported?

    Here is a post that I assembled for another who needed to continue to run his PowerPC applications in Lion/Mt. Lion:
    Unfortunately you got caught up in the minor miracle of Rosetta.  Originally licensed by Apple when it migrated from the PowerPC CPU platform that it had used from the mid-1990's until the Intel CPU platform in 2006, Rosetta allowed Mac users to continue to use their library of PPC software transparently in emulation.
    However, Apple's license to continue to use this technology expired with new releases of OS X commencing with Lion (and now Mountain Lion).  While educational efforts have been made over the last 6 years, the fact is that Rosetta was SO successful that many users were caught unaware UNTIL they upgraded to Lion or Mountain Lion.
    Workarounds:
    1. If your Mac will support it, restore OS X Snow Leopard;
    2.  If your Mac will support it, partition your hard drive or add an external hard drive and install Snow Leopard into it and use the "dual-boot" method to choose between your PowerPC software or Lion/Mt. Lion;
    3.  Upgrade your software to Intel compatible versions, or find alternative software that will open your data files;
    3.  Install Snow Leopard (with Rosetta) into Parallels:
                                  [click on image to enlarge]
    Full Snow Leopard installation instructions here:
    http://forums.macrumors.com/showthread.php?t=1365439
    NOTE: STEP ONE of the instructions must currently be completed on a Snow Leopard or Lion Mac and the resulting modified Snow Leopard.cdr install file can then be moved over to your Mountain Lion Mac for completion of the remaining steps.
    NOTE 2:  Computer games with complex, 3D or fast motion graphics make not work well or at all in virtualization.

  • What does this error mean? There was an error in the App Store. Please try again later. (100)

    what does this error mean? There was an error in the App Store. Please try again later. (100)

    I have the same problem and thought it might be related to moving to Denmark. My app store account was set up for USA and then the error number in parentasis was (13). After changing the profile to Denmark the number changed to (100), like yours

  • While importing a CD into my iTunes library I kept getting the following error message- iTunes library cannot be saved- An unknown error occurred (-54).  What does this error mean and what can I do about it??

    While importing a CD into my iTunes library I kept getting the following error message- iTunes cannot be saved- An unknown error occurred (-54).  what does this error mean and what can I do about it??

    The CD I imported (in the above post) is now not in my iTunes library. Any help would be appreciated .

Maybe you are looking for