Singletons and multithreading question

Hi, I had a class created as a singleton as it was only used in one place. However since Ive now multithreaded the part of the program that calls the singleton code so it could be called twice at the same time.
If the method being called initializes all its variables within the method, is that method safe to be called in a mutli-threaded env or not ?
If it in my situation all variables are declared within the method except a precompiled javax.xml.XPathExpression class, the same one is used to parse an Input Source, the input source itself is created within the method. I
think I am having concurrency problems , (SAXParser Exceptions) and I think it is because of this XPathExpression class but cannot clearly understand why.
What is the correct solution, I dont want to initilize the XPathExpression within the method because the method is called many times always for the same expression, dropping the singleton and creating new instances of the class on every call would be even worse. I require multithreading to improve concurrency is there a safe Multi Singleton pattern that i should be using ?

There are two issues:
a) is the singleton object safe for multithreaded use
b) how do I safely create a singleton in a multi-threaded application
The answer to (a) depends on the class. It sounds from your description that you are using an object (the XPathExpression) that might not be thread-safe. I can't tell you if it is or not. Assuming it is not you either need to synchronize this method so that all threads will go through it (and use the expression) one at a time - which may defeat the purpose of multi-threading - or else you need a way to use multiple instances of these expressions in different threads. As I'm not familiar with these classes I can't tell you what you can and can't do concurrently.
There are a number of answers to (b). Construction via static initialization is the simplest and safest. If you want lazy initialization and the class that holds the reference to the singleton must be loaded even if the singleton isn't needed, then lookup the initialize-on-demand-holder-class idiom (see Josh Bloch's "Effective Java" item 48)

Similar Messages

  • Singleton and non singleton in webdynpro java

    Hi All,
    where we use singleton and non singleton in webdynpro application.please send me with any example (scenario).
    Regards
    Anand

    Hello Anand,
    I think that your question is for u201CWeb Dynpro Javau201D forum..
    Please use the correct forum for your question.
    In general:: http://wiki.sdn.sap.com/wiki/display/WDJava/SingletonandNon-Singleton+Nodes
    There is example at : http://wiki.sdn.sap.com/wiki/display/WDJava/DynamicUIGeneration
    u201CWelcome to Web Dynpro Java! u201C  Wiki : http://wiki.sdn.sap.com/wiki/display/WDJava/WelcometoWebDynproJava%21
    Thank you and best regards, Natalia Khlopina

  • Report and multithreading

    Hi all,
    Here is a simple question concerning report and multithreading.
    I want to execute two sequences, called sequence A and sequence B, in parallel from a MainSequence. Both sequences should be execute in new threads. Here is my problem: The generated report of my MainSequence didn't include the sub reports of sequences A and B. How can I do this ?
    In my MainSequence report, I only saw that the Sequence A and Sequence B are called from my MainSequence, but there is no information about sub step in sequences A and B....
    I know that it's possible to do this using the append options, when report file already exist, but I didn't like this method...
    Any idea?
    Thanks.
    Vincent

    At the end of your main sequence, insert one Wait step for each thread you launched. Configure the Wait steps to wait for the threads you launched. The results for the threads will appear in the report under the results for the Wait steps.

  • ATG Pipeline and Multithreading

    Hi,
    I have couple of questions with respect to ATG Pipeline and Multithreading. The scenario is like - to process multiple threads and each thread is a pipeline chain.
    Now the pipeline chain contains components which are globally scoped.
    Questions -
    1) Is ATG pipeline thread safe?
    2) If the pipeline contains sequence of global-scoped components, is the pipeline still a threadsafe?
    Thanks!

    Pipelines are mend to be thread safe as they can be called from multiple HTTP request thread. The run process method accepts object which is usually a map of all the input parameters and PipelineResult which encapsulates any response parameter. So though being a global scoped component it always work on local objects (Not dealing with member variables).

  • What's the differences between a singleton and a class with static methods

    Hi everybody.
    My question is in the subject. Perhaps "differences" is not the good word. The positive and negative points ?
    Imagine you have to write a connection pool, sure you gonna choose a singleton but why ?
    Thank you very much.

    A class is a class. Java doesn't have (and I wish it
    did) a static outer class. Any class can extend
    another class or implement an interface.A Class object cannot extend or implement anything - it is not under programmer control in any way. You can create a class which implements interfaces, but calling static methods is completely unrelated. Interfaces only affect instance methods, not class ones. I think all of your comparison to C++ is actually confusing you more. In Java, there is a real class object at runtime, as opposed to C++.
    YATArchivist makes a good point about being able to
    serialize, altho I've not met that desire in practice.
    Maybe a concrete example would help.
    mattbunch makes another point that I don't understand.
    A class can implement an interface whether it sticks
    its data in statics or in a dobject, so I guess I
    still don't get that one.See my comment above. Static methods are free from all contractual obligations.
    I prefer instance singletons to singleton classes because they are more flexible to change. For instance I created a thread pool singleton which worked by passing the instance around, but later I needed two thread pools so I made a slight modification to the class and poof! no more singleton and 99% of my code compiled cleanly against it.
    When possible, I prefer to hand the instance off from object to object rather than have everything call Singleton.instance() since it makes changes like I mentioned earlier more feasible.

  • Account with an icon of a face and a question mark

    Same issue of other user in Yosemite Apple Support.
    Following advises on that thread I also installed the ETRECHECK software tool, report is as follows:
    Problem description:
    At the login screen I find an icon with a face and a question mark in it - with a message it needs an update.
    EtreCheck version: 2.1.5 (108)
    Report generated 02 gennaio 2015 12:37:26 CET
    Click the [Support] links for help with non-Apple products.
    Click the [Details] links for more information about that line.
    Click the [Adware] links for help removing adware.
    Hardware Information: ℹ️
      MacBook Pro (13-inch, Mid 2012) (Verified)
      MacBook Pro - model: MacBookPro9,2
      1 2.5 GHz Intel Core i5 CPU: 2-core
      16 GB RAM Upgradeable
      BANK 0/DIMM0
      8 GB DDR3 1600 MHz ok
      BANK 1/DIMM0
      8 GB DDR3 1600 MHz ok
      Bluetooth: Good - Handoff/Airdrop2 supported
      Wireless:  en1: 802.11 a/b/g/n
    Video Information: ℹ️
      Intel HD Graphics 4000
      Color LCD 1280 x 800
    System Software: ℹ️
      OS X 10.10.1 (14B25) - Uptime: 1:22:54
    Disk Information: ℹ️
      APPLE HDD HTS545050A7E362 disk0 : (500,11 GB)
      EFI (disk0s1) <not mounted> : 210 MB
      Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
      Macintosh HD (disk1) / : 498.89 GB (467.03 GB free)
      Encrypted AES-XTS Unlocked
      Core Storage: disk0s2 499.25 GB Online
      MATSHITADVD-R   UJ-8A8 
    USB Information: ℹ️
      Apple Inc. FaceTime HD Camera (Built-in)
      Apple Computer, Inc. IR Receiver
      Apple Inc. BRCM20702 Hub
      Apple Inc. Bluetooth USB Host Controller
      Apple Inc. Apple Internal Keyboard / Trackpad
    Thunderbolt Information: ℹ️
      Apple Inc. thunderbolt_bus
    Gatekeeper: ℹ️
      Mac App Store and identified developers
    Launch Daemons: ℹ️
      [loaded] com.adobe.fpsaud.plist [Support]
    User Login Items: ℹ️
      iTunesHelper Applicazione (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)
      Dropbox ApplicazioneHidden (/Applications/Dropbox.app)
    Internet Plug-ins: ℹ️
      FlashPlayer-10.6: Version: 16.0.0.235 - SDK 10.6 [Support]
      Flash Player: Version: 16.0.0.235 - SDK 10.6 [Support]
      QuickTime Plugin: Version: 7.7.3
      Default Browser: Version: 600 - SDK 10.10
    Safari Extensions: ℹ️
      Pin It Button [Installed]
      Save to Pocket [Installed]
      Add To Amazon Wish List [Installed]
    3rd Party Preference Panes: ℹ️
      Flash Player  [Support]
    Time Machine: ℹ️
      Time Machine not configured!
    Top Processes by CPU: ℹ️
          14% WindowServer
          3% hidd
          2% Safari
          1% Dock
          0% fontd
    Top Processes by Memory: ℹ️
      333 MB com.apple.WebKit.WebContent
      155 MB mds_stores
      137 MB Safari
      137 MB Finder
      86 MB Dropbox
    Virtual Memory Information: ℹ️
      7.76 GB Free RAM
      4.88 GB Active RAM
      3.28 GB Inactive RAM
      1.26 GB Wired RAM
      4.73 GB Page-ins
      0 B Page-outs
    Diagnostics Information: ℹ️
      Jan 2, 2015, 11:15:06 AM Self test - passed
      Jan 2, 2015, 12:06:57 AM /Library/Logs/DiagnosticReports/Dropbox109_2015-01-02-000657_[redacted].cpu_res ource.diag [Details]
    ---------- is there any troubleshooting for delete that fake account every time I start my Macbook Pro?
    thanks and regards
    Edoardo

    Smiley face with a ? means a bootable system is not found.
    There maybe  a problem with either system software or hard drive itself.
    Try this.
    Repair Disk
    Steps 2 through 8
    http://support.apple.com/kb/PH5836
    Best.

  • Performance issue and functional question regarding updates on tables

    A person at my site wrote some code to update a custom field on the MARC table that was being copied from the MARA table.  Here is what I would have expected to see as the code.  Assume that both sets of code have a parameter called p_werks which is the plant in question.
    data : commit_count type i.
    select matnr zfield from mara into (wa_marc-matnr, wa_marc-zfield).
      update marc set zfield = wa_marc-zfield
         where werks = p_werks and matnr = wa_matnr.
      commit work and wait.
    endselect.
    I would have committed every 200 rows instead of every one row, but here's the actual code and my question isn't around the commits but something else.  In this case an internal table was built with two elements - MATNR and WERKS - could have done that above too, but that's not my question.
                DO.
                  " Lock the record that needs to be update with material creation date
                  CALL FUNCTION 'ENQUEUE_EMMARCS'
                    EXPORTING
                      mode_marc      = 'S'
                      mandt          = sy-mandt
                      matnr          = wa_marc-matnr
                      werks          = wa_marc-werks
                    EXCEPTIONS
                      foreign_lock   = 1
                      system_failure = 2
                      OTHERS         = 3.
                  IF sy-subrc <> 0.
                    " Wait, if the records not able to perform as lock
                    CALL FUNCTION 'RZL_SLEEP'.
                  ELSE.
                    EXIT.
                  ENDIF.
                ENDDO.
                " Update the record in the table MARC with material creation date
                UPDATE marc SET zzdate = wa_mara-zzdate
                           WHERE matnr = wa_mara-matnr AND
                                 werks = wa_marc-werks.    " IN s_werks.
                IF sy-subrc EQ 0.
                  " Save record in the database table MARC
                  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                    EXPORTING
                      wait   = 'X'
                    IMPORTING
                      return = wa_return.
                  wa_log-matnr   = wa_marc-matnr.
                  wa_log-werks   = wa_marc-werks.
                  wa_log-type    = 'S'.
                  " text-010 - 'Material creation date has updated'.
                  wa_log-message = text-010.
                  wa_log-zzdate  = wa_mara-zzdate.
                  APPEND wa_log TO tb_log.
                  CLEAR: wa_return,wa_log.
                ELSE.
                  " Roll back the record(un save), if there is any issue occurs
                  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
                    IMPORTING
                      return = wa_return.
                  wa_log-matnr   = wa_marc-matnr.
                  wa_log-werks   = wa_marc-werks.
                  wa_log-type    = 'E'.
                  " 'Material creation date does not updated'.
                  wa_log-message = text-011.
                  wa_log-zzdate  = wa_mara-zzdate..
                  APPEND wa_log TO tb_log.
                  CLEAR: wa_return, wa_log.
                ENDIF.
                " Unlock the record from data base
                CALL FUNCTION 'DEQUEUE_EMMARCS'
                  EXPORTING
                    mode_marc = 'S'
                    mandt     = sy-mandt
                    matnr     = wa_marc-matnr
                    werks     = wa_marc-werks.
              ENDIF.
    Here's the question - why did this person enqueue and dequeue explicit locks like this ?  They claimed it was to prevent issues - what issues ???  Is there something special about updating tables that we don't know about ?  We've actually seen it where the system runs out of these ENQUEUE locks.
    Before you all go off the deep end and ask why not just do the update, keep in mind that you don't want to update a million + rows and then do a commit either - that locks up the entire table!

    The ENQUEUE lock insure that another program called by another user will not update the data at the same time, so preventing database coherence to be lost. In fact, another user on a SAP correct transaction, has read the record and locked it, so when it will be updated your modifications will be lost, also you could override modifications made by another user in another luw.
    You cannot use a COMMIT WORK in a SELECT - ENDSELECT, because COMMIT WORK will close each and every opened database cursor, so your first idea would dump after the first update. (so the internal table is mandatory)
    Go through some documentation like [Updates in the R/3 System (BC-CST-UP)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCSTUP/BCCSTUP_PT.pdf]
    Regards

  • How can i restore my iphone 5s as i forgot my icloud password and sec questions

    I bought a new iphone 5s  (32G Gold)
    and when I connect it to itunes asked me to restore from my old iphone 4
    with all my account settings and passwords.
    but I have a problem with my account for icloud password and security questions because my cloude id is *************** and with no problem with my apple id "*****************", I tried to restore my new iphone after I turned off find my iphone from icloud setting and when its restore was finished the iphone is locked and asked me to unlock the iphone with a ****************** that I forget the password and security questions and when I tried to enter my account id "**************** with no problem with its password it says to me "this account can't unlock this iphone"
    when I visit tradeline (Apple products dealer) I found no answer and they adviced me to contact apple directly.
    Name : Alaa Rashed Abd el Hafiz
    Country : egypt
    <Personal Information Edited by Host>

    First, remove your personal information from your post.  That's not needed here.  This is a public forum, and it is unwise to provide your personal data online.
    Second, here's how you reset your password and/or security questions.
    How to reset your Apple ID password.
    Go to iforgot.apple.com and type in your Apple ID, then click 'Next'.
    Verify your date of birth, then click 'Next'.
    You'll be able to choose one of two methods to reset your password, either E-Mail Authentication or Answer Security Questions.
    If neither method works, then go to https://getsupport.apple.com
    (If you see a message that says 'There are no products registered to this Apple ID, simply click on 'See all products and services')
    Choose 'More Products & Services', then 'Apple ID'.
    A new page will open.
    Choose 'Other Apple ID Topics', then 'Lost or forgotten Apple ID password'.
    Click the blue 'Continue' button.
    Select the contact option that suits your needs best.
    How to reset your Apple ID security questions.
    Go to appleid.apple.com, click on the blue button that says 'Manage Your Apple ID'.
    Log in with your Apple ID and password. (If you have forgotten your Apple ID password, go to iforgot.apple.com first to reset your password with a password recovery email)
    Go to the Password & Security section on the left side, and click on the link underneath the security questions that says 'Forgot your answers? Send reset security info email to [email]'.  This will generate an automated e-mail that will allow you to reset your security questions.
    If that doesn't work, or  there is no rescue email link available, then click on 'Temporary Support PIN' that is in the bottom left side, and generate a 4-digit PIN for the Apple Account Security Advisor you will be contacting later.
    Next, go to https://getsupport.apple.com
    (If you see a message that says 'There are no products registered to this Apple ID, simply click on 'See all products and services')
    Choose 'More Products & Services', then 'Apple ID'.
    A new page will open.
    Choose 'Other Apple ID Topics', then 'Forgotten Apple ID Security Questions'.
    Click the blue 'Continue' button.
    Select the contact option that suits your needs best.

  • I have purchased music with my old apple id, old computer and old email. My old email and computer are not available anymore and I dont remember my password and securtiy question anymore. How can I authorise my old apple id to authorise the new computer?

    Hi, I have a new computer and new apple id. I've purchased music with my old computer, email and apple id.
    I cant access now the previously purchase music, because it wants to authorize the new computer to play the
    music. I cant remember password and security questions for my old id and the old email doest exist anymore.
    What can I do?

    Hi, Carmen. 
    Thank you for visiting Apple Support Communities. 
    If you need to reset you security questions, do not know the answers and no longer have access to that email account, see the last sentence under Note in step 5.
    You'll be asked to answer 2 of your 3 security questions before you can make any modifications. If you are unable to remember your answers, you can choose to send an email to your rescue email to reset your security questions.
    Note: The option to send an email to reset your security questions and answers will not be available if a rescue email address is not provided. You will need tocontact iTunes Store support in order to do so.
    Rescue email address and how to reset Apple ID security questions
    http://support.apple.com/kb/ht5312
    Cheers,
    Jason H.

  • Spam filtering solution for iPhone and a question.

    I've read a lot of posts about spam filtering for the iPhone and have yet another solution and a question. I use SpamSieve and I am not affiliated with them in any way. The nice thing about SpamSieve is that if it is the first rule in your Mail.app rule set any mail that follows has already been filtered. All you need to do then is create another rule that redirects email to what ever mail account you choose. Since my ISP allows multiple accounts, I will simply create an iPhone@myISP account.
    Now the question. Is it possible to write an applescript that will turn the redirect rule on or off so that I don't have to dig into the rules section of Mail to get this done?
    Thanks

    Is it possible to write an applescript that will turn the redirect rule on or off so that I don't have to dig into the rules section of Mail to get this done?
    not at present time

  • HT1553 I did the back up as instructed... Installed a larger hard drive and followed the restore instructions... Now I get a white screen with a folder icon and blinking question mark. When trying to set startup with new drive I get a bless tool error...

    I did the back up as instructed... Installed a larger hard drive and followed the restore instructions... Now I get a white screen with a folder icon and blinking question mark. When trying to set startup with new drive I get a bless tool error... Help!!

    If you have installed a new hard drive , you will need to have formatted it in Disk Utility correctly. This may explain your problem.
    Boot  into your 10.6 Install disk again at the top menubar > Utilities > select Disk utility and in there select your new hard drive, and select the tab Erase and choose to make the format as  Mac OS Extended Journaled. When that is finished look in the main window to make sure that the partition map scheme says GUID Partition Table.
    Now go to the Restore tab and reinstall from your backup.

  • Trying to download songs on iTunes and it's asking for "my 1st car I owned" and other questions that I never answered. It won't let me download anything til I answer them. Can you help me?

    Trying to download songs on iTunes and it's asking for "my 1st car I owned" and other questions that I never answered. It won't let me download anything til I answer them. Can you help me?

    You need to contact Apple to get the questions reset. Click here, phone them, and ask for the Account Security team, or fill out and submit this form.
    (94816)

  • I want to integrate SMS gateway to Cisco ISE 1.2 and my question is SMS notifications are supported for Guest self−registration

    I want to integrate SMS gateway to Cisco ISE 1.2 and my question is 
    SMS notifications are supported for Guest self−registration Services ? or it should be done by Sponsor 

    I'm not sure I understand the question.  Do you want to log in to the Sponsor Portal using AD credentials?
    Create an Identity Source Sequence using AD as an Authentication Source.  Go to Administration > Identity Management > Identity Source Sequences.  Either Edit or +Add a Sequence and choose from the Authentication Sources shown.
    Then choose that Identity Source Sequence by going to Administration > Web Portal Management > Settings.  Double-click Sponsor from the Left Menu and click Authentication Source.  Choose the Identity Source Sequence.  Click Save.
    I hope this helps.
    Please Rate Helpful posts and mark this question as answered if, in fact, this does answer your question.  Otherwise, feel free to post follow-up questions.
    Charles Moreton

  • SBO Ebook: Certification and Interview Questions and Answers

    Hi, please permit me to use this forum to introduce you to this ebook titled: [SAP BUSINESS ONE SOLUTION CONSULTANT CERTIFICATION REVIEW AND INTERVIEW: QUESTIONS, ANSWERS AND EXPLANATIONS|http://www.ebookmall.com/ebook/277772-ebook.htm]
    This book consists of real life and scenario based review questions and answers on SAP Business One solution certification examinations with Booking Codes/Certification ID: C_TB1200_04, C_TB1200_05 and C_TB1200_07. It covers the SAP Business One Solution Consultant curriculum namely:
    &#61607; TB 1000 - SAP Business One – Logistics
    &#61607; TB 1100 - SAP Business One – Accounting
    &#61607; TB 1200 - SAP Business One – Implementation and Support
    The book is targeted at:
    &#61607; SAP Business One Consultants preparing for the Solution certification exams (C_TB1200_04, C_TB1200_05 and C_TB1200_07)
    &#61607; SAP Business One Solution Consultant Job Seekers
    &#61607; SAP Business One Solution Consultant recruiters
    &#61607; SAP Business One Implementation team
    &#61607; SAP Business One Project Managers
    In this book, you will find:
    &#61607; SAP Business One Solution Consultant Certification Areas of Concentration (AoC)
    &#61607; SAP Business One Solution Consultant Certification Curriculum
    &#61607; Things you must know about the SAP Business One Solution Consultant Certification Examination.
    &#61607; SAP Business One Certification review questions and detailed answers
    &#61607; SAP Business One Interview questions and detailed answers
    It can be downloaded at http://www.ebookmall.com/ebook/277772-ebook.htm.

    Hi Dan,
    Thanks for your observation, comment and review.
    1. As a matter of fact, since many features of SAP B1 has not changed, just as you asserted, I took cognizance of new enhancements to the solution over the various releases, especially as it relates to the functionalities. By extension however, most questions for prior releases applies to the “successor” release.
    Furthermore, there was a mix-up in the download. Ideally, you should have three sections in the book. Section I (release 2004, by extension - 2005 and 2007 releases); Section II (release 2005, by extension - 2007 release) and Section III (release 2007). The document has been reviewed. Hence, everyone that bought the book before 29th of April 2008 should visit my [blog|http://blogs.ittoolbox.com/sap/kehinde/archives/sap-business-one-solution-consultant-ebook-review-notice-24053] on how to get a copy of the revised version within 24 hours at no extra cost. I regret any inconveniences. PLEASE DO NOT LEAVE YOUR EMAIL ADDRESS ON THIS FORUM.
    2. On localization, SAP Business One has more than 10,000 installations across the world. The book is not intended to be "localization specific". It is intended to serve as a certification review for functionalities that cuts across board with a mix of localized functionalities. I am sure you found in there a number of localization questions for other countries like UK. My advice for individuals using the book is to identify which questions apply to their localization.
    While I await your review of the [revised version|http://www.ebookmall.com/ebook/277772-ebook.htm] as an SAP Business One advisor, I believe you will agree with me that it is an invaluable resource for preparing for the certification exam and also technical interview sessions. 
    Thanks

  • Flash Security Settings and Random Questions not Displaying

    Hey folks,
    I created a Captivate 4 project with 3 slides and a question pool of about 70 questions in which I am randomly pulling in. I am using IE7 and Flash 10. Publishing in Flash 10. If I publish or view in Preview in a web browser the project launches, plays the first 3 slides, and then goes blank when the first question should appear. Note: previewing the project AND publishing the project as an .exe does launch and display all the questions correctly. It ends up being a flash security issue. I went to the adobe site and via the Adobe Flash Player Security Manager" I entered in the main .SWF captivate-generated file as a trusted file and then re-ran the published captivate project and it ran correctly. Question is ... what do I need to do to set up flash or my project so I don't have to do this for every new project that I deploy? I don't want to have the users have to go in and add whatever I deploy as a trusted file. It's also a little confusing as to why the first three slides played and it stopped at the questions ... seems like if it's not a trusted file, that it wouldn't run at all.
    Thanks for any help!
    Chris

    Hello again
    I think I'd be investigating a temporary web server to host on until things are ready. Here's where it will help.
    By providing files to the end users, if you are copying files over you end up having to explain how to save the files. You then have to walk them through setting the Flash Security so they can properly view. It all just becomes a pain in the kazoo.
    If you can find some server space, you simply upload the content and provide a link for the users to view the content.
    Other than that, if you are insistent that copying is the way to fly, I might suggest you establish a known location where you want everyone to copy their files. Perhaps C:\TestFolder. Then provide some instruction on how to configure the folder with the relaxed Flash Security. From there forward, anything they copy to the folder should need no security adjustment.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

Maybe you are looking for