How to preserve object identity across different VMs

Posted by wheleph on Stack Overflow See other posts from Stack Overflow or by wheleph
Published on 2010-06-08T00:39:34Z Indexed on 2010/06/08 0:42 UTC
Read the original article Hit count: 257

Filed under:
|
|
|
|

To be specific let me illustrate the question with Spring http-remoting example.

Suppose we have such implementation of a simple interface:

public SearchServiceImpl implements SearchService {
    public SearchJdo processSearch(SearchJdo search) {
        search.name = "a funky name";
        return search;
    }
}

SearchJdo is itself a simple POJO.

Now when we call the method from a client through http-remoting we'll get:

public class HTTPClient {
    public static void main(final String[] arguments) {
        final ApplicationContext context = new ClassPathXmlApplicationContext(
            "spring-http-client-config.xml");
        final SearchService searchService =
            (SearchService) context.getBean("searchService");

        SearchJdo search = new SearchJdo();
        search.name = "myName"; 
        // this method actually returns the same object it gets as an argument
        SearchJdo search2 = searchService.processSearch(search);
        System.out.println(search == search2); // prints "false"
    }
}

The problem is that the search objects are different because of serializaton although from logical prospective they are the same.

The question is whether there are some technique that allows to support or emulate object identity across VMs.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring