Acquiring a lock on an object?

I've browsed through the threading and synchronization tutorial, but I don't fully understand it. I currently have a class with an array, which may be modified by an external thread. I also have another thread that counts the number of non-null elements in the array, makes an array of that size, and then copies over all of the non-null contents. Although it is very rare, occasionally the array-copying thread will count n objects in the array, then the array will be modified by the other thread and will now have n+1 elements in it, then my array copier will try to put n+1 elements into its n-sized array.
How do I prevent this from happening?

And in the case you described, the object you synchronize on should not be the array. Why not? Because your description reveals a misunderstanding. You cannot change the size of an array, so your statement "then the array will be modified by the other thread and will now have n+1 elements in it" must actually mean "then the other thread creates a new array that has n+1 elements in it". So anything that was synchronizing on the original array has no effect on anything that is now synchronizing on the new array -- which is a different object.

Similar Messages

  • Error : MDSConfig failed to acquire write lock??

    Hi,
    Changes that I know used to flow, don't flow anymore, and I was suspecting something was wrong with the changelog followup.
    I guess I was right, cause I see this in the meta-.xxx.log:
    MDSConfig failed to acquire write lock 'MDS_E_FAILED_TO_ACQUIRE_WRITE_LOCK' (80042212), wlock=(fe3f1c40), rlock
    =(fe3f1c10), readlocks=4, writelockstate=0
    No mention in the admin guide obvioiusly.
    Anyone knows what this might mean? The config is on a dedicated DS instance, and no errors found there.
    MDS = 5.0SP1
    DS = 5.1SP1
    Thanks,
    Wim

    i sometimes see such messages on startup
    normally they go away a few minutes later.
    another solution is to stop everything (meta directory processes, and the LDAP's containing the MV and the NetscapeRoot), then start only the LDAP's, wait a few minutes, start the join-engine,
    it seems some objects in the ldap still/already have a write lock on them (myabe from a previous connection), when the join-engine tries to write to them

  • Thread waiting to lock on an object that it has already locked

    I have a thread in my thread dump where it is "waiting to lock" on an object, but it already has acquired the lock. How can this be possible?
    "TP-Processor778" daemon prio=1 tid=0x230dde38 nid=0x1168 waiting for monitor entry [0x0f184000..0x0f185fa0]
    at sun.net.www.protocol.file.Handler.openConnection(Handler.java:63)
    - waiting to lock <0x40fbf128> (a sun.net.www.protocol.file.Handler)
    at sun.net.www.protocol.file.Handler.openConnection(Handler.java:55)
    - locked <0x40fbf128> (a sun.net.www.protocol.file.Handler)
    at java.net.URL.openConnection(URL.java:943)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

    If object.wait() is called, an existing lock is released so another thead can lock the object.
    If you object.notify() but hold the lock in another thread, the first thread will not resume until it has required the lock.

  • Failed to acquire exclusive lock on client session - Webdynpro

    Anyone experience this below intermittent error on Webdynpro - e.g. Display Leave Summary functions ?  If user retry/revisit the same screen again. it will be working fine.
    Having some hard to to get thread dump at those short and intermittent moment.
    Any suggestions are welcome.
    Found this note below but doubt it will help at this moment.
    Web Dynpro error page, known error situations, error codes
    SAP Note Number: 1113811 
    NW/EP 7.0 SPS13
    #2#sap.com/pb/PageBuilder#com.sap.tc.webdynpro.services.session.LockException: Thread SAPEngine_Application_Thread[impl:3]_21 failed to acquire exclusive lock on client session ClientSession(id=(J2EE11441500)ID1662520351DB00529024001059157699End_1898143411). Existing locks: LockingManager(ThreadName:SAPEngine_Application_Thread[impl:3]_21, exclusive client session lock: ClientSessionLock(SAPEngine_Application_Thread[impl:3]_16), shared client session locks: ClientSessionSharedLockManager([]), app session locks: ApplicationSessionLockManager([]), current request: sap.com/pb/PageBuilder).Hint: Take a thread dump of the server node to find the blocking thread that causes the problem.
         at com.sap.tc.webdynpro.clientserver.session.ClientSession$LockingManager.lock(ClientSession.java:1511)
         at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:233)
         at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:150)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:62)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:53)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

    Hi,
    Check this,
    ESS SC Import Problem
    Thanks and Regards,
    gopal.sattiraju

  • Failed to acquire exclusive lock on client session ClientSession

    HI all.
    when I login the Portal as a MSS role,I want to see about the data of employee(about 20000 employee).
    some page can't open succeed.The error:
    500   Internal Server Error
      SAP NetWeaver Application Server 7.00/Java AS 7.00 
    Failed to process request. Please contact your system administrator.
    Error Summary
    While processing the current request, an exception occured which could not be handled by the application or the framework.
    If the information contained on this page doesn't help you to find and correct the cause of the problem, please contact your system administrator. To facilitate analysis of the problem, keep a copy of this error page. Hint: Most browsers allow to select all content, copy it and then paste it into an empty document (e.g. email or simple text file).
    Root Cause
    The initial exception that caused the request to fail, was:
       com.sap.tc.webdynpro.services.session.LockException: Thread SAPEngine_Application_Thread[impl:3]_27 failed to acquire exclusive lock on client session ClientSession(id=(DSAPBPRD_DPP_01)ID2006199550DB11722229503911854949End_53412655). Existing locks: LockingManager(ThreadName:SAPEngine_Application_Thread[impl:3]_27, exclusive client session lock: ClientSessionLock(SAPEngine_Application_Thread[impl:3]_29), shared client session locks: ClientSessionSharedLockManager([]), app session locks: ApplicationSessionLockManager([]), current request: sap.com/pb/PageBuilder).Hint: Take a thread dump of the server node to find the blocking thread that causes the problem.
        at java.lang.Throwable.<init>(Throwable.java:56)
        at com.sap.exception.BaseException.<init>(BaseException.java:145)
        at com.sap.tc.webdynpro.services.exceptions.WDException.<init>(WDException.java:61)
        at com.sap.tc.webdynpro.services.exceptions.WDException.<init>(WDException.java:54)
        at com.sap.tc.webdynpro.clientserver.session.ClientSession$LockingManager.lock(ClientSession.java:1511)
        ... 20 more
    Edited by: cui joe on Jun 16, 2009 5:36 AM

    HI,thanks very much.
    Because our data is very huge,so some leader login the system will get the error.I check the st22,It realy found the error:
    Time limit exceeded.
    The program "SAPLRHDB" has exceeded the maximum permitted runtime without
    interruption and has therefore been terminated.
    If I should increase the system profile parameter "rdisp/max_wprun_time"?
    Can else I should turn other parameter?

  • Could not acquire a lock

    Hello,
    I'm trying to activate and smartform but every time I'm getting this dump:
    Error Text of the Database: "[ASE Error SQL12205]Could not acquire a lock
    within the specified wait period. SERVER level wait period=2400 seconds,
    spid=259, lock type=exclusive row, dbid=4, objid=1260735642, pageno=5821264,
    rowno=5. Aborting the transaction.#"
    I've checked the LWM and HWM, and this paramteres have default value 2147483647.

    I don't think the LWM an HWM values will be relevant to this situation.  It sounds like some other process is holding an incompatible lock on this row for a long time, and your client is choosing to time out rather than continue to block.
    Use a query against master..syslocks (or wade through the output of sp_lock) to look for such a process.
    -bret

  • Why does Livecycle Designer need to lock scripting on objects with children that are fragments??

    Can someone tell me why Livecycle need to lock scripting on objects with children that are fragments??
    I mean, just because I have a fragment (which you can't edit the script for), why does Livecycle need me to NOT edit say the initialise event on the Main form.
    Yes, I can remove my fragments, edit and reinsert.  Also if the event already has a script, I can edit the xml.  But neither of these are terribly convenient.
    Couldn't there be a better way?

    The purpose of the fragment is to create re-usable or standard components. In most cases the fragment is not created by the same person designing the form and they do not want the from designer to modify any part of the fragment (it is a separate XDP file). There may be code in that fragment that relies on the structure that exists. If you have the rights you can always edit the fragment and when your PDF is created the changes will be picked up.
    If you want to be able to modify the fragment while it is in Design mode sounds to me like you want to add a component to the object library. This will allow you to have a reusable piece of a form that you can modify on a form by form basis. To do this simply build the piece that you want. Lasso the entire form and drag it onto the Custom library. When you release it a dialog will pop up allowing you to name your component. Now on any form design you can drag your new component onto the canvas and all methods/properties and code will come with that component (allowing you to modify it for that form as you see fit).
    Note that you can create your own libraries to hold your components if you see fit. Also if you put your libraries on a shared drive, you can share components between Designers.
    Paul

  • HR OM  LOCK and UNLOCK object!

    hi!
    some one know HR OM object's LOCK and UNLOCK object ?
    thank you very much!

    Hi ,
    these can be used to lock/unlock  om objects..
    CALL FUNCTION 'HR_ENQUEUE_OBJECT'
           EXPORTING
                PLVAR            = ACT_ENQK-PLVAR
                OTYPE            = ACT_ENQK-OTYPE
                OBJID            =  ACT_ENQK-OBJID
                ENQUEUE_ONCE     = ' '
           IMPORTING
    call function HR_DEQUEUE_OBJECT
    These can be used to lock the OM objects..
    Br,
    Vijay.

  • Error: Acquire running lock failed: 256 with HA after upgr. to 2.1.5

    Hello,
    after upgrading the 2 servers in server pool from 2.1.2 to 2.1.5 using yum, all vms throw:
    Error: Acquire running lock failed: 256
    when trying to start them. HA-infrastructure-check works well from OVMM 2.1.2 (not upgraded yet) and if we disable HA for the server pool, the vms come up. Shared storage is on NFS
    We have the following in /var/log/xen/xend.log:
    [2009-06-26 14:52:21 2649] DEBUG (XendDomainInfo:87) XendDomainInfo.create(['vm', ['name', '470_vm215'], ['memory', '1024'], ['on_reboot', 'restart'], ['on_crash', 'restart'], ['vcpus', 1], ['on_xend_start', 'ignore'], ['on_xend_stop', 'ignore'], ['uuid', '14205f6a-12cc-42da-a32e-06f30b6288d4'], ['bootloader', '/usr/bin/pygrub'], ['bootloader_args', '-q'], ['image', ['linux']], ['device', ['vbd', ['uname', 'file:/OVS/running_pool/470_vm215/system.img'], ['dev', 'sda'], ['mode', 'w']]], ['device', ['vif', ['bridge', 'xenbr0'], ['mac', '00:16:3E:32:CD:FC'], ['type', 'netfront']]], ['device', ['vkbd']], ['device', ['vfb', ['vncunused', '1'], ['vncpasswd', 'XXXXXXXX'], ['vnclisten', '0.0.0.0'], ['type', 'vnc'], ['display', 'localhost:11.0'], ['xauthority', '/root/.Xauthority']]]])
    [2009-06-26 14:52:21 2649] ERROR (XendDomainInfo:452) VM start failed
    Traceback (most recent call last):
    File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 430, in start
    self.acquire_running_lock();
    File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 2891, in acquire_running_lock
    raise XendError('Acquire running lock failed: %s' % status)
    XendError: Acquire running lock failed: 256
    [2009-06-26 14:52:21 2649] DEBUG (XendDomainInfo:1881) XendDomainInfo.destroy: domid=None
    [2009-06-26 14:52:21 2649] ERROR (XendDomainInfo:92) Domain construction failed
    Traceback (most recent call last):
    File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 90, in create
    vm.start()
    File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 430, in start
    self.acquire_running_lock();
    File "/usr/lib/python2.4/site-packages/xen/xend/XendDomainInfo.py", line 2891, in acquire_running_lock
    raise XendError('Acquire running lock failed: %s' % status)
    XendError: Acquire running lock failed: 256
    [2009-06-26 14:52:21 2649] DEBUG (XendDomainInfo:1881) XendDomainInfo.destroy: domid=None
    and in /var/log/xen/xend-debug.log:
    ha_set_dlm_lock ['14205f6a-12cc-42da-a32e-06f30b6288d4', '470_vm215'] =>
    failed: <Exception: create lock('/dlm/ovm/4205f6a12cc42daa32e06f30b6288d4') failed. <OSError: [Errno 26] Text file busy: '/dlm/ovm/4205f6a12cc42daa32e06f30b6288d4'>
    StackTrace:
    File "/opt/ovs-agent-2.2/OVSXHA.py", line 371, in ha_set_dlm_lock
    fd = os.open(lock_path, os.O_CREAT | os.O_NONBLOCK)
    >
    StackTrace:
    File "/opt/ovs-agent-2.2/OVSXHA.py", line 379, in ha_set_dlm_lock
    raise Exception("create lock('%s') failed. %s" % (lock_path, errmsg))
    Any ideas?
    Thanks, Olaf

    suk wrote:
    1. To delete the database, which database are you referring to? I'm referring to the ovs-agent database:
    1. Stop the agent: # /etc/init.d/ovs-agent stop 2. Delete the database: # rm -f /etc/ovs-agent/db 3. Start the agent: # /etc/init.d/ovs-agent start If you have Oracle VM Manager v2.1.5 (which you should have upgraded before your servers, btw), you can now try using the "Restore" option for the server pool. Click on the Server Pool in the manager and hit "Restore" -- this will send the configuration data back down to the agents in the pool. Alternatively, you may need to de-register the servers in your pool and re-register them.
    2. To re-imported the guests, how?In Oracle VM Manager -- if you recreate the pool, you have the option of "Importing" both VM Templates and VM Guests. Deleting the pool in the Manager does not delete your guests as long as you ensure that you DO NOT select "Remove Working Directories".

  • Locking on Method objects?

    my understanding is that:
    public synchronized void counter() { usageCounter++;  }is equivalent to:
    public void counter() {
      synchronized(this) {
        usageCounter++;
    }locking the whole object has some overhead. could this overhead be eliminated using this approach:
    public void counter() {
      Method m = this.getClass().getMethod("counter", new Class[0]);
      synchronized(m) {
        usageCounter++;
      } // and this method is the only way to modify "usageCounter"
    }what exactly does this do?
    my understanding is that a Method object is static and immutable . they are created when the relevant class is loaded.
    so, it really makes no difference that i sync on the " +counter()+ " method object when i am in " +counter()+ ". right? i could just as easily sync on maybe the " +counter123()+ " method object.
    btw, do immutable objects have mutable locks? my code compiles/runs correctly. though, i've not done extensive testing to see if i get a "ConcurrentModificationException"
    anyway, this is all hypothetical. just trying to learn about java. and maybe someday i can answer, rather than post, questions.
    thanks.

    what exactly does this do?Uses a Method object as a lock. Note: a Method is only a representation of the compiled method. You cannot get access to the compiled method.
    Method object is static and immutable .Its neither. You can have more than one per real method (not static in any sense of the word) and they are mutable. e.g. setAccessible()
    they are created when the relevant class is loaded.No. When the class is loaded, neither the compiled method (created when you call the method) nor the Method object are created are loaded (The first Merthod is created the first time it is needed and then copied as required, the Class has a soft reference to a cached copy which means the cached copy is discarded on a full gc, potentially recreated later)
    it really makes no difference that i sync on the " counter() " method object when i am in " counter() ". right? Locking on a object means different threads can be accessing different objects at once, but two threads cannot access different synchronized methods on the same object at once.
    In your case you have the opposite. Different thread would not be able to concurrently access a method (even for different objects) but would be able to access different methods of the same object.
    Except, as Method is mutable, getMethod() returns a different object each time, so your lock effectively does nothing.
    The purpose of synchronization is to protect mutable data i.e. fields of an object, not protect methods.
    immutable objects have mutable locks?All objects have locks, immutable object are no different. (Java doesn't know the object is immutable, perhaps it should, but it doesn't)
    i've not done extensive testing to see if i get a "ConcurrentModificationException"You could be waiting a while as this only occurs on Iterator for some collections. Note: you can get this exception with just one thread.
    just trying to learn about java. and maybe someday i can answer, rather than post, questions.This is a good place to do that.

  • CKPT locks the system objects and blocks other sessions

    CKPT locks the system objects and blocks other sessions
    Oracle Version 10.2.0.4
    OS : HP UX 11.31 Itanium
    SQL> select * from v$lock where block=1;
    ADDR KADDR SID TY ID1 ID2 LMODE
    REQUEST CTIME BLOCK
    C0000009FCC2B348 C0000009FCC2B368 1100 RO 65559 1 2
    0 3877 1
    SQL> select program from v$session where sid=1100;
    PROGRAM
    oracle@ctqanhr1 (CKPT)
    As a workaround we flush the buffer cache with the below command
    SQL> alter system flush buffer_cache;
    however the issue reoccurs after some times.
    Edited by: 965132 on Dec 2, 2012 9:59 PM

    other reference:
    CKPT Questions
    The temporary workaround is to set "_db_fast_obj_truncate"=FALSE in that particular case.
    Regards,
    sgc
    Edited by: Samuel G. Cristobal on 03-dic-2012 8:48

  • Error when acquiring central lock - Urgent

    Hi ,
    I was trying to access the documents in Collaboration Team room. When i clicked the details of the folders under "documents and Links" room part, i got null pointer exception.
    Then i tried analysing the default trace and i could see the logs are getting generated continuously with the below mentioned error. No clue on what it implies..
    default trace files are getting filled up very fast and new files are generated.
    Errors:
    1. error when acquiring central lock (The lifetime can not be the user-session, because currently no user is logged in. Creating locks for the system-user is not allowed
    2. com.sapportals.wcm.WcmException##com.sapportals.wcm.WcmException.WcmException(90) Error when acquiring central lock com.sap.engine.services.applocking.exception.AppLockingTechnicalLockException: The lifetime can not be the user-session, because currently no user is logged in. Creating locks for the system-user is not allowed.
    Can anyone help me.?
    Thanks in advance
    Siva
    Pts will be awarded for helpful answers

    Hi All,
    SAP note 894884 solved my issue.
    Rgds,
    Siva

  • [svn:bz-trunk] 21661: Avoid calling throwNotSubscribedException() from inside synchronized blocks to prevent potential issues acquiring the lock .

    Revision: 21661
    Revision: 21661
    Author:   [email protected]
    Date:     2011-07-21 06:21:07 -0700 (Thu, 21 Jul 2011)
    Log Message:
    Avoid calling throwNotSubscribedException() from inside synchronized blocks to prevent potential issues acquiring the lock.
    Checkin-Tests: Pass
    QA: Yes
    Doc: No
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/client/FlexClient.java

  • Error: Acquire running lock failed: 256

    Can anyone help me? I did everthing that documentation says,but can't start my Virtual Machine .The error below picks up
    Error: Acquire running lock failed: 256

    VM server and VM manager both on virtual box
    Oracle VM 3.1.1

  • Multiple blocking locks on same object

    we have a database that is providing a great deal of application 'freezing' due to lock problems that were not experienced before moving to a new 10g database environment.
    one of the items i believe to be of interest is the fact that when this 'freezing' occurs then a look at the database locks reveals that more than one TX exclusive blocking lock is held on the same database object without any waits showing.
    my understanding is that this should not be the case? that only one user should possess the exclusive transaction level lock and that the other user should only have an outstanding request for this same level lock?
    any information you can provide would be most appreciated.
    thanks in advance.

    You would need to find out the sql the application is executing when those locks freeze like that. From there determine if there is a logical syntax issue or get the explain plan to ensure it isn't for example an update statement on a massive table that has improper indexing.
    Also, do you see other sessions blocking other sessions as orafad suggested? In this scenario my original explanation is different. If the locks are all chained on waiting on another session, that means the first session that is blocking is updating the same data that the waiters are wanting.
    In my opinion you need to find out the exact SQL causing these locks to ensure it is an issue with one of your applications. Determining the performance of that query is a must.
    The only weird thing is you say there is no waits taking place....did you look in v$session_wait?
    Lee

Maybe you are looking for

  • Mic and cam

    this may be a dumb question,  but how do I know if there is a built in mic and webcam on my computer.  My husbands says it is here like his laptop but I do not see how to turn on the cam or know if the mic is working   I have a new hp pavillion, 24 i

  • Connecting MacBook to Sony Bravia via DVI-HDMI!

    Hi I am having major issues with my Macbook connecting to my Sony Bravia KDL-32V4000 I now have 2 different DVI-HDMI leads as well as the Apple Mini-DVI-DVI and still have absolutely no luck. The Macbook is picking up the Television absolutely no bot

  • Recording to VCR using Digital Adapter

    I've been kicking around getting the digital adapter instead of the STB for 2 of our TVs (they're in an office and guest room).  I understand we wouldn't have the interactive guide, PPV, etc. BUT- what I don't know is can you schedule the VCR to reco

  • Bursring control file from Lunix to windows server

    Hi all I have devloped an rdf file to return payment data I want to store the output on sharefolder on windows server is it possible to move the file (FTP) from the application server which is Linex to my windoes server using XML Bursting Control Fil

  • Just installed ODT 11.1.0.6.20 but can't find Oracle Explorer

    I downloaded and installed the latest ODT but there is no Oracle Explorer under the View menu option of VS2008. Installation went fine with no errors. I could see the new debugging options under the Tools menu option. I even uninstalled just the deve