The unnecessary use of synchronize in code example in the Dev Guide

I ask this question with some trepidation, I'm sure someone out there will be able to explain it and then I'll feel really stupid asking.  But that's...

Using a HTTP connection code sample in the developer's Guide (I checked 4.3 and 4.5, and it's the same in these two levels), use synchronized in two places that I don't understand.

(1) getUrl() - Code follows

/**
* Retrieve the URL. The synchronized keyword ensures that one
* thread at a time can call this method on a ConnectionThread object.
*/
public synchronized String getUrl() {}
Return _theUrl;
}

I understand the comment, and it is sometimes useful force methods you want to synchronize.  But not this method in vessel closed.  If anything, there are more cases of use of this mechanism for the recovery method in this code.

(2) around of the fetch block - following Code:

/ * Make sure that pull requests are not missed
* While the received data is processed.
*/
{Synchronized (this)}
Open the connection

When I see a synchronization block like that, I guess it's a little shared code that can be executed by multiple threads, which this clearly isn't.  So why is it synchronized?

In fact, I think that 'design' is a testament to this example may be imperfect.  I think it would be better to have a new Thread for each connection, or have a queue (synchronized) URL addressing.

As evidenced by another thread on this forum, the developers make these samples as Gospel and try to use them.  So if this is wrong, perhaps we could fix.  But maybe it just me being a lumberjack full.  Wouldn't be the first time...  And won't be the last!

It seems that this example has been designed with a base defense to the following (if no synchronization) scenario:

Event thread request _start = true.

Threaded starts the connection.

Event thread again pray _start = true.

Threaded end connection, defines _start = false.

Net result: the second event thread request is not met.

That being said, the guys are right: this design is mediocre at best.  In the scenario above, the second request of event thread is blocked while the thread of the connection ends... and as everyone knows at this point, blocking the event thread usually leads to a world of pain.  There are certainly better approaches that can be used here, and probably the easiest way to this problem is just to have the best control flow, such as not allowing not a new connection request while one is already underway.  Certainly the synchronization adds excessive complexity to this problem and distracts from what the sample is trying to demonstrate: a simple HTTP connection.

For this example, and the extraction, I will recommend to the authors that both be reviewed and be a structure such that these samples are as simple as possible.  Thanks to Peter marchywka for their suggestions.  Comments like yours, it's how we identify areas for improvement.

Tags: BlackBerry Developers

Similar Questions

  • Question on Passivation / Activation in the Dev Guide example

    ADF 11 g

    Hello

    I load certain values in the session UserData in my application PrepareSession module.
    If I understand things that I have to passivate/activate this information.

    However the example in the merger Dev Guide page 39-19 for passivation
    seems to be missing the appellant to super.passivateState.

    Is this correct?

    Best regards
    Paul

    Surprisingly, no.. The method of the superclass is basically a no-op. This method is not involved in the passivation of State transactional and nontransactional standard; It's just for custom data. Standard passivation takes place at passivateState (byte [], int, int).

  • Code sample NFC in the development guide does not

    Hello.

    I just wrote a quick Hello world app for reading and writing NDEF records, based on the code provided in the development Guide.

    I use the MiFare Ultralight tags. However, it does not work.

    I could write NDEF only once during the tests, but after that I was unable to write the tags again or delete them using my application. However, the application of NFC demo included with the BB is able to write.

    Thinking that the tag doesn't have enough space to store the nested NDEF message of the dev guide, I changed the code (reader and writer) use only a title and url records, without success.

    I also tried to change the parameter listener of NDEFRecord.TNF_WELL_KNOW to NDEFRecord.TNF_ANY, so read the labels already written with the demo included in the BB application, but it has no effect. I have read that sporadically with the two types, but most of the time the BB does not detect everything just the tag.

    Now, I know that:

    • The tag is readable and writable, because I read and written in the plain format ISO-14443-3 and the BB demo readings and Scripture in NDEF.
    • The tag is unlocked and able NDEF (inspected a target using DetectionListener object)
    • A few times I was able to write an NDEF tag, but then it is not readable by my application nor by BB demo group.
    • I have read several times, but most of the time it fails.
    • Tried to erase the label before writing, but does not work.

    I use exactly the same code that appears in the development guide and a BB 9360.

    Finally, I solved the problem. It turns out that my tags (Mifare Ultralight) have only 64 bytes of total storage, so the example NDEFMessage in the development Guide (root NDEF Sp record with two folders nested inside) is too big to be stored when the text exceeds a few words.

    With regard to the NDEFTagConnection class, I found that the erase method throws exceptions, and that the append method is problematic. The only method that worked for me was the write method (who wrote the entire tag).

  • Store changed from the United Kingdom to China using my old zip code. Now cannot get back. Payment type is NONE, but get requests by charging to add card details.

    Store changed from the United Kingdom to China the other day using my old zip code. Now can not return to the United Kingdom. Payment type is NONE, but get requests in billing add card details that they are not everything. Postal code is changed back to UK. Phone is iOS 4 s 9.2.1. Any ideas how to get back?

    Hi Sandyback,

    Thank you for your participation in the communities of Support from Apple.

    I see that you have changed the country associated with your Apple (iTunes Store account) ID, and now ask you to provide a method of payment. This happens when changing the country on an existing Apple ID, according to why I can't select None when I change my Apple ID payment information?

    If you have changed your country or region

    When you change the country or the region of an Apple ID, you must provide a payment method and update your billing options. If you want to delete your payment method after you change the country or region, you can change your payment information to none.

    You will not be able to see or select the no payment option for one of these reasons. If you don't want to use a credit card, you can use another form of payment, for example, a gift card.

    Sincerely.

  • How can I get the amount of free disk space using the space using windows 7 Please share example using GetDiskSpace

    How can I get the amount of disk space by using windows 7 Please share example using GetDiskSpace I already studied http://digital.ni.com/public.nsf/allkb/9958B8E473C4EF1786256BBC0053B64F

    Reading your question a little more in detail, I doubt if you are using the Win32 GetDiskFreeSpace API function (including my previous post is the solution) of the function GetDiskSpace from the Toolbox of the programmer.

    With respect to the other, it works even with capacity greater than 2 GB disks, but you must use the appropriate formatting code to display the returned value. I updated my example to display the total of free space in the debug output window and added a comparison with the value of 3 GB using UInt64TypeCompareUInt box to tools programming interface.

  • Used to synchronize some titles in the Playlist?

    I hope someone can restore my sanity. I recently signed up for music apple and wanted to add a few old songs to a playlist. There are about 30 songs, and then I tried to sync them to my Apple Watch. All titles in the playlist are downloaded on my iPhone. However, there are three songs that do not appear to Sync? More precisely-Sweet Emotion (Aerosmith), Psycho Killer (Talking Heads) and Big Shot (Billy Joel). But since it was in a greatest hits albums, maybe there is a problem... but even after adding them to my list of the original albums (toys in the attic, the 52nd Street and the talking Heads 77). Used to synchronize the SAME SONGS.  Why?  Any ideas?

    It can help to experiment with the addition of problematic tracks to your playlist synchronized one at a time.

  • My mcbook used to synchronize my iphone6 it again to get the new version on computer and I have the new version of iTunes versionThis (11.4) is the current version.

    My mcbook used to synchronize my iphone6 it again to get the new version on computer and I have the new version of iTunes versionThis (11.4) is the current version.

    iTunes version 12.3.2 is the latest version of iTunes.

    http://www.Apple.com/iTunes/download/

  • Play files TDMS in Matlab - problems with the code example

    I want to use the TDMS files for storing data and offline analysis in Matlab, version 2009b (whether on Mac OS10.6 or Windows XP).

    To test the data import in Matlab, I tried the example of http://digital.ni.com/public.nsf/allkb/0EEADA99DC7D00A4862572E30037C3A2 , but without success.

    I tried with or without the definition of the path (as it is explained on the page that I mentioned before) at the beginning and return the following errors:

    with:

    ??? With the help of ==> loadlibrary error > deltempfiles to 559

    nilibddc_m.i.

    Error in ==> loadlibrary to 452

    deltempfiles (DelFiles);

    Error in ==> Read_TDMData at 7

    LoadLibrary (['\nilibddc' examplePath], hfile);

    without:

    ??? With the help of ==> loadlibrary error > deltempfiles to 559

    nilibddc_m.i.

    Error in ==> loadlibrary to 452

    deltempfiles (DelFiles);

    Error in ==> Read_TDMData to 36

    LoadLibrary (NI_TDM_DLL_Path, NI_TDM_H_Path);

    I found a few posts on the issue, dating back to 2006 and 2007, which do not lead to a satisfactory solution, and hoped that, now, there will be a solution to my problem.

    Thank you very much

    Remco

    Have you copied the nilibddc.dll somewhere else?

    If Yes, you copy all the contents of the dev/bin folder? Including subfolders?

  • Can I use a working android code to build a pure Java application. I don't want the port directly.

    Can I use a working android code to build a pure Java application. I don't want the port directly.

    I want to convert an android app for Bb 10 working versions of a Java for BB 6.0 and 7.0 application verson etc.

    Laughing out loud
    Android use j2se, bb os use j2me (+ extensions).
    a few basic java classes and functionality (collections, reflection etc) will be unavailable on java bb as he (resp. j2me) is based on java 1.3/1.4

    in my experience most logical profession can be reused with minimal changes (such as the use of vectors instead of the list, etc.), but UI has to be redone completely.

  • The Group Policy settings do not allow the use of a PIN code at startup Bitlocker Windows 8

    Hello

    I hope you can help.

    I tried to implement the encryption on my new laptop Lenovo Twist with windows 8, but get the following error.

    ERROR: An error has occurred (code 0 x 80310060):
    Group Policy settings do not allow the use of a PIN code start. Please choose a
    other BitLocker startup option.

    I tried to change local policy settings...

    1. Go to Local computer policy > Computer Configuration > administrative templates > Windows components > Bitlocker Drive Encryption > Operating System Drives
    2. Open the key require additional start authentication
    3. Activate this key, then assign the require startup PIN with TPM TPM configure startup PIN

    .. .but always not the same error.

    Help, please. He drives me crazy!

    Hello

    Thanks for choosing Microsoft Community to post your question!

    According to your description, it seems that you have problems with activation PIN code on startup.

    Refer to the suggestions from this link and check.

    http://social.technet.Microsoft.com/forums/en/w7itprosecurity/thread/c3b5e90d-89fd-4e95-AF97-723b045eb41b

    For more help, I suggest you ask your question in the TechNet Forum. http://social.technet.Microsoft.com/forums/en-us/w8itprosecurity/threads

  • Outlook not available mail and used to synchronize with the Mail application.

    Original title: Outlook unavailable Mail

    My outlook mail said * address email is removed from the privacy * unavailable and used to synchronize.  I rebooted, reset my mail, reset my computer.  No luck.

    Outlook.com has had an interruption of the service last week that lasted a few days intermittently.  Probably, you were one of the affected users (it depends on what server your account performed).  They kept everyone has indicated that they have restored the system to service on status.live.com.

  • After purchasing the cloud creative and used for 2 months (for example), so I don't use it for 3 months. How is it? I don't have to pay the tariff for each month, or is it possible to only pay when I use it again? To resume: if I use it for 5 months a

    After purchasing the cloud creative and used for 2 months (for example), so I don't use it for 3 months. How is it? I don't have to pay the tariff for each month, or is it possible to only pay when I use it again? To resume: if I use it for 5 months a year, I have to pay for only those 5 or 12 months?

    No, if you have a subscription according to the type of subscription, you will have to pay each month or year until that you cancel.

    If you think you would use the apps for only three months, then you will not need three months, then our month to month plan would be best for you because it can be cancelled at any time it does not come with an annual contract for more information see the link below

    Adobe - General conditions of subscription

    Kind regards

    Bani

  • We just do the last update on Photoshop - that's why whenever we now open photoshop you have to select all the toolbars we want.  They used to be there for example, layers, tools, colors, etc., but now, we have to select each time

    We just do the last update on Photoshop - that's why whenever we now open photoshop you have to select all the toolbars we want.  They used to be there for example, layers, tools, colors, etc., but now, we have to select each time

    You look at the new start screen and files recent screen.  Press ESC to return to your usual workspace.

  • Do not install the 'Online Store' Application and the Code example

    The following error occurs when you try to install
    the file imported, online_store_installer_1.0.sql
    the application of the "shop online" and the Code examples.
    downloaded yesterday from:

    http://www.Oracle.com/technology/products/database/application_express/packaged_apps/packaged_apps.html#store

    I had created beforehand the user "eshop".

    I have the Version 3.1.1 of the Apex



    1 error has occurred
    NOT COMPATIBLE (your export may contain calls not supported by your version of the application.)


    Connected to the workspace: ESHOP

    Export the WorkspaceID file: 1150504199010437
    Export Application file: 129
    Version of the export file: 2007.01.08
    Analysis of export in the form of schema file: EBA
    Origin of the application: the application has been exported from a different workspace.

    Hello

    Maybe you need to grant more \n(Assurez-vous ESHOP?
    try to give this user DBA \n(Assurez-vous and see the results.

    See you soon,.

    Peter

  • myRIO C code examples

    Hi all

    I'm just starting to watch myRIO for use for programming in C labs

    with the students.

    Depending on the resources, there is a link to the C code examples, for example. on

    http://www.NI.com/Tutorial/14619/en/

    but this link is broken. Examples are still available?

    Thank you

    Select this option.

    Hi Mark,

    This is the link you're talking to the step 3 download NOR myRIO C examples and Documentation? I tried it myself and it worked fine.

    If it is this link, you are talking about try this: http://www.ni.com/download/labview-myrio-toolkit-2014/4949/en/

    I hope it works for you,

Maybe you are looking for

  • How to find an old version of Firefox that I can download?

    I need my Norton toolbar to work with Fire Fox. I know that it works with 17.0.1, I'm on another computer. How can I download this older version?

  • Photo upload for web site... where are my albums?

    Here's my situation: I am on several forums online and often need to upload a photo or two.  I click on the "upload photo" icon within the web site and then select something like a 'Browse folders' menu  On my computer, I can then go down to 'media'

  • Error system 1355: "Error_no_such_domain".

    Original title: Impossible to type my new password! I click on the start icon connected, and then click Control Panel. Then I click on user accounts. I click on the account which I want to change my password. I logged onto the account which I want to

  • My computer is slow, what can I do to speed it up?

    My computer is slow, what can I do to speed it up? My speedtest is 6.53 et.73 mbps, it seems that it takes forever for my ISP find and get the website to download!

  • Norton internet Security 2010

    Hello How to re - install Norton internet Security 2010 only on HP Pavilion e9280t? My PC came without any reinstallation CD/DVD. Thank you.