Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

synchronization on services


This is low-priority - we have a work-around for the issue described, but
   - you may be interested in the issue itself
- we're interested in answers to related questions it brings up.

We would like to support a range of services that call each other and we would also like to protect naive developers from building services that can go multiple-threaded without 'permission' from the developer.
Our service, which uses Java syncnronization on an object, doesn't work in this scenario:-
- call the first service on the same PU, which
- calls the second service on the same PU, which
- does the synch call.

We get a timeout exception around the "synchronized( additionalProcessingSynchronizationLock )" call.

The service clients (which are on the same PU as the services called) both use the ExecutorRemotingProxyConfigurer to access the proxy.

The PUAdditionalService.additionalProcessing() calls the KeyGenerationService.setLastAllocatedPrimaryKey().
Both use a synchronized lock on a different instance object in the service implementation.

The call to the PUAdditionalService.additionalProcessing() throws a timeoutException (log20090225163408.txt – line 1398)

The code for PUAdditionalService.additionalProcessing() is shown below

public void additionalProcessing() {
                                                            log.info( "LLLLL additionalProcessingSynchronizationLock WAIT..." );
        synchronized( additionalProcessingSynchronizationLock ) {
                                                                log.info( "LLLLL ... additionalProcessingSynchronizationLock GRABBED" );
            /* method uid:svcAdditionalMethod@f40e5a2d-3da1-4e64-9d19-cc4f40a90251: .......... method code goes below this comment
            log.info("***************** in additionalProcessing() - counting to 1000");
            int count = 0;
            while ( count < 1000 )
                count ++ ;
            log.info("***************** in additionalProcessing() - counted to 1000");
                log.info(">>>>>>>>>>>>>> calling setLastAllocatedPrimaryKey with 'Brokerage', 'ExternalOrderId', 'new Integer(0)'");
                GsbProxies.KeyGenerationService.setLastAllocatedPrimaryKey( "Brokerage", "ExternalOrderId", new Integer(0) );
            catch( Exception err )
                log.info( ">>>>>> UNABLE TO SEED THE PRIMARY KEYS for 'Brokerage', 'ExternalOrderId', 'new Integer(0)'");
                StringWriter sw = new StringWriter();
                err.printStackTrace( new PrintWriter(sw) );
                log.info( ">>>>>> STACK TRACE WAS " + sw);
            log.info("***************** in additionalProcessing() - bye");
            /* method end:svcAdditionalMethod@f40e5a2d-3da1-4e64-9d19-cc4f40a90251: .......... method code goes above this comment

1. Why do we get the timeout error?

2. Can you comment on services calling each other ad infinitum and are there any restrictions in doing this?

3. To protect users against inadvertent multi-threading, is there a better what than putting "synchronized" on the service implementation?

4. We notice that sync remoting uses space filters and we could understand if the service was hanging on the invocation call but
it appears to be hanging on the synchronization call. Can you explain this?

5. The log have the smell of another thread starting to run the service for some reason that then gets hung up on the synchronization lock, but we can't see any reason why it should
(unless there's some smarts in the service handling?).

Does that ring any bells?


  1. log20090225163408.txt

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2009-02-27 10:22:41 -0600

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

Few questions:
- Any chance you had lots of concurrent rapid remote calls going ?
- Any simple test case you can post that reproduce this?
- Why you are using sync remoting and not executors? Executors are faster and more scalable.
See Executors example:


answered 2009-02-27 22:45:43 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2009-02-27 10:22:41 -0600

Seen: 119 times

Last updated: Feb 27 '09