When do we need to declare method as Synchronised

Hi Everyone,
I have a common class with number of methods which are used by some other servlet classes.It may possible that more than one class use same method at same time.
All method are staic because I want to access method with class name instead of object.Do i need to declare all method as Synchroinised.There is no global varaible.
reply as soon as possible.It is very urgent.
Thanks

If for example your class stores some values which can be updated by any1 then the methods should be syncronised to prevent them for entering a state where 2 events occur at the same time one reading and one writing.
I use the syncronised method to ensure the my internal data class is not compromised. These methods are generally 4 times slower i think.
Hope this helps

Similar Messages

  • When do I need to declare multiple usages of the same component

    I have a noddy WD4A component with a main view containing only ViewContainerUI elements. Each container has a sub-view embedded implementing some functionality I am playing with. One of these views implements a select option by using the WDR_SELECT_OPTIONS component. I have got this working. Then I decide to make a copy of the view in order to test some modifications. I embed this in a new ViewContainerUI element on the main view.
    So now I have 2 sub views implementing the same select option. When I run it, the 2nd select option appears in the first view as a duplicate. The only way I can fix this is by declaring a second usage (of WDR_SELECT_OPTIONS) in the component and using this in the copied view.
    So now I have 2 WDR_SELECT_OPTIONS component usages declared (with different names) so that my 2 views can coexist on the screen. Is this really necessary? Had it been the same view implementing both select options fair enough - but these are 2 different views.
    If the views were not displayed at the same time, could I have declared and used just 1 component usage?
    Peter

    I have still not succeeded in dynamically creating a 2nd select Option and getting it to display in a View Container (called VC_SOD). The code compiles and runs but the select option does not display. This is hopefully something I will never need to do in reality. Just an exercise.
    The code that is commented out is the original standard technique of using a select_option usage. There is probably more then 1 fundamental mistake in the code
    method WDDOMODIFYVIEW .
      DATA: LT_RANGE_TABLE TYPE REF TO DATA,
            RT_RANGE_TABLE TYPE REF TO DATA,
            READ_ONLY TYPE ABAP_BOOL,
            TYPENAME TYPE STRING.
      DATA: LR_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER,
            L_REF_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.
    create the used component
      L_REF_CMP_USAGE = WD_THIS->WD_CPUSE_SELECT_OPTIONS( ).
    Here we copy the usage just for the hell of it.
      DATA lr_component_usage type ref to if_wd_component_usage.
      L_REF_CMP_USAGE = L_REF_CMP_USAGE->CREATE_COMP_USAGE_OF_SAME_TYPE( name = 'SELECT_OPTIONS2' ).
      IF L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
        L_REF_CMP_USAGE->CREATE_COMPONENT( ).
      ENDIF.
    *call the interface controller method init_selection_screen to get the helper class
    WD_THIS->M_WD_SOD = WD_THIS->WD_CPIFC_SELECT_OPTIONS( ).
      data L_INTF_CONTROLLER type ref to IWCI_WDR_SELECT_OPTIONS.
      L_INTF_CONTROLLER ?= L_REF_CMP_USAGE->GET_INTERFACE_CONTROLLER( ).
    data lo_view_controller type ref to if_wd_view_controller.
    data lo_view_usage TYPE REF TO if_wd_rr_view_usage.
    data lo_view_cnt_assignment TYPE REF TO if_wd_rr_view_cnt_assignment.
    data lo_view type ref to if_wd_view.
    lo_view_controller = wd_this->wd_get_api( ).
    lo_view_usage = view->get_view_usage( ).
    try and see what is going on
    data lo_view_container_assignments type WDRR_VCA_OBJECTS.
    lo_view_container_assignments = lo_view_usage->GET_VIEW_CNT_ASSIGNMENTS( ).
    lo_view_cnt_assignment = lo_view_usage->create_view_cnt_assignment( name = 'VC_SOD' assigned_container = 'VC_SOD' ).
    try and see what is going on
    lo_view_container_assignments = lo_view_usage->GET_VIEW_CNT_ASSIGNMENTS( ).
    init the select screen
    WD_THIS->M_HANDLER = WD_THIS->M_WD_SOD->INIT_SELECTION_SCREEN( ).
      WD_THIS->M_HANDLER = L_INTF_CONTROLLER->INIT_SELECTION_SCREEN( ).
      WD_THIS->M_HANDLER->SET_GLOBAL_OPTIONS(
                                  I_DISPLAY_BTN_CANCEL  = ABAP_FALSE
                                  I_DISPLAY_BTN_CHECK   = ABAP_FALSE
                                  I_DISPLAY_BTN_RESET   = ABAP_FALSE
                                  I_DISPLAY_BTN_EXECUTE = ABAP_FALSE ).
    create a range table that consists of this new data element
      LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'S_CARR_ID' ).
    add a new field to the selection
      WD_THIS->M_HANDLER->ADD_SELECTION_FIELD( I_ID = 'S_CARR_ID' IT_RESULT = LT_RANGE_TABLE I_READ_ONLY = READ_ONLY ).
    endmethod.

  • Do I need to declare a transaction in this case?

    I am struggling to understand when it is necessary to declare my own transaction to ensure the data is properly updated.
    For example, in the following code, which is part of a java bean in the EJB project, KeyFacade is a stateless session bean tied to the entity "Key". it is a standard EJB created with the netBeans 5.5 wizard. I have changed no defaults.
    Do I need to declare a transaction, commit the transaction and close it when I use the "KeyFacade.edit(key);" in order to ensure the database is updated? Or is it automatically done because the .edit() method uses the entityManager and the persistence is container managed?
    Would it make a difference if this bean was part of a WAR project?
        public BigInteger getNextKey(String tableName){
            KeyFacadeLocal KeyFacade = this.lookupKeyFacade();
            Key key = KeyFacade.findByTablename(tableName);
            long nextKey = key.getKeyvalue();
            BigInteger BINextKey =BigInteger.valueOf((int)nextKey);
            //  now update the table by incrementing the key value by 1
            long incrementKey = nextKey + 1;
            key.setKeyvalue(incrementKey);
            KeyFacade.edit(key);
            return BINextKey;
        }

    808239 wrote:
    I have a Map<Integer, List<T>> data, and all the lists are initialized using Collections.synchronizedList().Seems like overkill to me. Your Map also looks like a Multimap, of which there are several existing implementations.
    When I do the traversal, I want to traverse ALL lists in the map at the same timeI suspect not. What you want to do is to traverse each one in sequence.
    so I have to sync all lists as shown in the API doc as follows: ...Seems like overkill to me, and will probably result in a very slow Map (not that there's any problem with that if it's the right thing to do; in this case, I suspect it isn't).
    Is this approach ok?What are you trying to achieve? If you need full consistency for your iterators (ie, a snapshot of the entire Map at the time the iterator is created), you have a two choices (assuming you don't want to deal with update journals):
    1. Lock the Map.
    2. Clone the Map (and your clone() method should be synchronized).
    Of the two, the second seems best to me, but neither is all that wonderful.
    However, if all you need is weak consistency - that is to say, what you return reflects the state of the Map when Iterator.next() is called - all you really need to do is make sure that your Lists are synchronized when you do the read.
    Since the List updates are the responsibility of your Map (I'm still presuming this is some sort of Multimap implementation), there's no real need to synchronize them; just synchronize the Map's own update methods.
    I'd also suggest that you make sure your getValue() method hands back an [url http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#unmodifiableList%28java.util.List%29]unmodifiable List to clients; otherwise they could start adding or removing values themselves.
    HIH
    Winston

  • When is it necessary to declare a transaction?

    I am struggling to understand when it is necessary to declare my own transaction to ensure the data is properly updated.
    For example, in the following code, which is part of a java bean in the EJB project, KeyFacade is a stateless session bean tied to the entity "Key". it is a standard EJB created with the netBeans 5.5 wizard. I have changed no defaults. Do I need to declare a transaction, commit the transaction and close it when I use the "KeyFacade.edit(key);" in order to ensure the database is updated? Or is it automatically done because the .edit() method uses the entityManager and the persistence is container managed? Would it make a difference if this bean was part of a WAR project?
        public BigInteger getNextKey(String tableName){
            KeyFacadeLocal KeyFacade = this.lookupKeyFacade();
            Key key = KeyFacade.findByTablename(tableName);
            long nextKey = key.getKeyvalue();
            BigInteger BINextKey =BigInteger.valueOf((int)nextKey);
            //  now update the table by incrementing the key value by 1
            long incrementKey = nextKey + 1;
            key.setKeyvalue(incrementKey);
            KeyFacade.edit(key);
            return BINextKey;
        }

    It depends where the method is defined. If it's defined as a business method of an EJB 3.0
    Session Bean, then the default is container-managed transactions with a transaction attribute
    of Required. That means if there is an existing transaction that is propagated into the business
    method invocation , the work performed within the method occurs within the incoming transaction.
    If there is no transaction propagated into the business method, the EJB container will automatically
    start a new one and commit it after the business method completes. This container-managed
    transaction demarcation behavior has nothing to do with what code is in the business method.
    You can change the transaction behavior of the EJB by using the @TransactionManagement
    and @TransactionAttribute annotations at either the class or bean level, as well as within ejb-jar.xml.
    The web tier doesn't have any notion of container-managed transactions. To start a global
    transaction from code running in the web tier, you would need to acquire the UserTransaction
    object and explicitly start and commit the transaction.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Error when calling a Webservice's public method in Forms10g

    Hi,
    I'm getting the following error when calling a webservice's public method, i'm using Forms10g 10.1.2.3
    java.rmi.RemoteException; nested exception is: HTTP transport error javax.xml.soap.SOAPException
    java.security.PrivilegedActionException javax.xml.soap.SOAPException
    Message send failed javax.net.ssl.SSLException SSL handshake failed X509CertChI have added the Jar containing the client proxy in both Classpaths(system variable and default.env), the jar has been made with jdk 1.4
    I also have tested the client proxy from jDeveloper and it's working there, but in Forms i'm getting this error.
    I guess my problem might be that i'm calling a webservice that is secured since the url starts with https
    what should i do to fix this ??
    Regards
    Carlos

    I understand, so i have a doubt, why the webservice works on jDeveloper ??Not just JDeveloper even soapUI and Neatbeans have a way of working without a client certificate installed.
    I do not know how they achieve it. I know that they work without a client DC.
    Cheers,
    PS: See this http://stackoverflow.com/questions/8887434/webservices-ssl-https, it offers a clue.
    The java programs run unhindered when one-way authentication is being used. These products ship with a digital certificate that is in the path of most popular CAs.
    Corollary, if the Web Server is configured for mutual authentication then you need to install and configure the client certificate in the tools.
    Edited by: Prabodh on Dec 5, 2012 8:36 PM

  • Do I need to declare my custom setter accessor in my interface/header file

    Hi there:
    I'm working through a Objective C tutorial. I've got an instance var that is declared in the var section of my @interface (in the header file). It's also declared as a property...all the defaults apply (assign and whatever else).
    @property int foo
    I also have it synthesized in my @implementation code.
    @synthesize foo;
    I need a custom setter though that checks out the value being assigned. Do I need to declare this setter function in my @interface section in the header file?
    -(void)setFoo:(int)newValue {
    if (newValue < minAllowed) {
    NSLog(@"Invalid foo: %i is less than the minimum of %i allowed", newValue, minAllowed);
    return;
    if (newValue > maxAllowed) {
    NSLog(@"Invalid foo: %i is greater than the maximum of %i allowed", newValue, maxAllowed);
    return;
    foo = newValue;
    } // setFoo()

    The @property statement is the declaration of the accessor methods whether they are synthesized or custom coded.
    For a fairly clear, detailed explanation see Accessor Methods in the +Memory Management Programming Guide for Cocoa+.

  • When do I need to use "void" ?

    When do I need to use "void" ?
    Thanks!!!

    When do I need to use "void" ?whenever you like to use it? although normally when e.g a method does not return a value
    public void sayHello() {
       System.out.println("Hello");
    }

  • Just need a simple method pls

    Hello, I don't want to learn the whole communications API just yet but I need a method that will send the RTS line high on a 9 pin common com port 1 say when true and off when false.
    Anyone have a method lying around I can use?
    Many thanks,
    Phil.

    Malcom,
    Thanks for pointing me to the Logitech USB microphone(s). It was a week before I could get to the nearest store selling them (turns out, Radio Shack has them). Then of course, needed more time to try out the new mic. I ended up "upgrading" to the Logitech headset (ear phones & boom mic) - it works perfectly. I also find the boom mic gives much better fidelity - my voice recordings sound like I'm an announcer on NPR now.
    Note to others seeking microphones for their Mac: get the USB connect type. The audio in-line on my Macs (past and present) gave "spotty performance" at best. With in-line audio connected mics, a Griffen iMic is usually needed to even get the mic to show up in "Sound" prefs. That device is merely a "USB simulator" of some kind - and I do not believe they last long enough to justify the $35 price.

  • The file is not compatible with this version of photoshop / CS2 error -- Same File : CS6 no error / CS2 error , I need trouble shooting method, Please

    the file is not compatible with this version of photoshop / CS2 error -- Same File : CS6 no error / CS2 error , I need trouble shooting method, Please

    Save with Maximize Compatibility in CS6.
    Choose Edit > Preferences > File Handling (Windows) or Photoshop > Preferences > File Handling (Mac OS). 
    From the Maximize PSD and PSB File Compatibility menu, choose any of the following: 
      Always 
    Then re-save your file so it can open in CS2

  • I have a ipod touch 2nd generation 8gb 4.2.1 im new to itunes i made a itunes account but it says i need a payment method is there anyway i can use my paypal if not is there a way to not have to use a payment method for itunes store please help ty

    i have a ipod touch 2nd generation 8gb 4.2.1 im new to itunes i made a itunes account but it says i need a payment method is there anyway i can use my paypal if not is there a way to not have to use a payment method for itunes store please help ty

    Create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    Using those instructions you may also be able to select PayPal if that is allowed in your country.

  • Acrobat Pro 9 for mac won't launch, reloaded from disk when hard drive needed to be replace. It's in applications folder but there is an X on the Acrobat Reinstall icon. What should I do.

    Acrobat Pro 9 for mac won't launch, reloaded from disk when hard drive needed to be replace. It's in applications folder but there is an X on the Acrobat Reinstall icon. What should I do.

    Hi Janice,
    What version of Mac OS are you using?
    Adobe does not recommend migrating the software from one disk to the other.
    Please run the setup file for Acrobat and reinstall the software. You might want to delete the existing version of Acrobat installed before reinstalling it.
    Regards,
    Rave

  • How many photos are too many photos for iPhoto? When do I need to upgrade to Aperture?

    How many photos are too many photos for iPhoto? When do I need to updgrade to Aperture?

    Hi Terrence,  this is what happens, all too often when I click on something, sometimes it takes me 5 more clicks on the mouse while moving the cursor around to get rid of it. The one below popped up as I clicked on my junk mail.
    The next one popped up when I was trying to get on to a site. This happens all the time. Don't know why it is happening. It happens on iPhoto, Aperture, everywhere I go, FaceBook...everywhere and at any time. So frustrating. I don't know if this is normal, but this was happening just before my last mac died a year ago.

  • I really need abstract static methods in abstract class

    Hello all.. I have a problem,
    I seem to really need abstract static methods.. but they are not supported.. but I think the JVM should implement them.. i just need them!
    Or can someone else explain me how to do this without abstract static methods:
    abstract class A {
    abstract static Y getY();
    static X getX() {
        // this methods uses getY, for example:
        y=getY();
       return new X(y); // or whatever
    class B extends A {
    static Y getY() { return YofB; }
    class C extends A {
    static Y getY() { return YofC; }
    // code that actually uses the classes above:
    // these are static calls
    B.getX();
    A.getX();I know this wont compile. How should i do it to implement the same?

    Damn i posted this in the wrong thread.. anyways.
    Yes offcourse i understand abstract and static
    But i have a problem where the only solution is to use them both.
    I think it is theoretically possible ot implement a JVM with support for abstract static methods.
    In fact it is a design decision to not support abstract static methods.. thats why i am asking this question.. how could you implemented this otherwise?
    There is an ugly soluition i think: using Aspect Oriented Programming with for example AspectJ.. but that solution is really ugly. So anyone has an OO solution?

  • Declaration method in users Class

    What's different between declaration method in these codes
    class Programm
    ClassA class1 = new ClassA();
    class1.TestMethod();
    public ClassA
    public void TestMethod()
    and
    class Programm
    ClassA.TestMethod();
    public ClassA
    internal static void TestMethod()

    There are 2 main differences.
    Your access modifier is different (public / internal). See this link for information about the 4 different access modifier. https://msdn.microsoft.com/en-us/library/ms173121.aspx
    Your first method has instance scope and the second one has a static/global scope. See this link on what the difference is between the 2. https://msdn.microsoft.com/en-us/library/aa645629(v=vs.71).aspx
    -Igor

  • When do i need to create SID adm user?

    Hi All,
       I am new to XI.I am trying to install XI on windows 2003 and sqlserver. I am done with the following without any error?
    1. OS and its service packs
    2. Sql Server and patches.
    3.Central instance
    4. DB instance
    5. Installed sap gui.
    I have logged in as administrator and installed the above stuff.
    1. When do i need to create <SID>adm user?
    2. Do i need to use <SID>adm to install the XI?
    3. When i logged in to sapgui, i am getting host name error. Do i need to change hosts file?
    Thank you
    Ganges Leaves
    Message was edited by: Ganges Leaves

    Hi Ganges,
    Pls have a look into this SAP Material
    https://websmp209.sap-ag.de/~sapidb/011000358700009389172004E.PDF
    http://help.sap.com/bp_bpmv130/Documentation/Installation/XI30InstallGuide.pdf
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a5550de0-0701-0010-a8b4-9fd433a080f3
    <i>4. When i logged in to sapgui, i am getting host name error. Do i need to change hosts file?</i>
    >>> Just ping the IP address and check that are u able to connect. Also check with Browser .
    Hope this helps,
    Regards,
    Moorthy

Maybe you are looking for