views:

66

answers:

3

Hi everyone,

I am creating a windows service in Java that writes data to an object. This object has to be accessible by another Java program. What is the best approach to take?

Thank you. Jack

A: 

Serialise the object to a File and read/write it with the other process! You can serialise it also to XML with frameworks like JAXB or XStream.

Another way is JMS, but it's hard to master.

Martin K.
@Martin,Thanks. I have considered your suggestion before but I would like to know if there are better approaches to this. There is a very long list of field-value pairs that are updated few times per second. So, is serialising the best solution?
On top of that, could someone point me to the tutorial for the most appropriate way to create Java service in windows?
The problem with using a file is ensuring the reader knows the file is not being updated and the writer doesn't attempt to update the file while it is being read.
Peter Lawrey
I suggest the following for a java service http://www.google.co.uk/search?q=java+service+wrapper
Peter Lawrey
Maybe you should use a distributed database like Hazelcast / Scalaris etc. They provide Currency control features, so your application performance should improve with many updates from different processes.
Martin K.
+1  A: 

I agree with the "put it in a file" approach, unless you elaborate on how the two java processes can "see" each other. Are they running at the same time? On the same machine? Etc. What data do you need to transfer?


If all applications and the service can write the data, you have a problem in determining which data is the correct (the one in application A or the service).

A simple approach to the "common datastore" problem could be a JNDI server which is included in most JEE servers like JBoss, where each configuration is told to read from the same JNDI server. I am unsure if clients can update information in JNDI but this is probably vendor specific.

Thorbjørn Ravn Andersen
@Thorbjorn,Yes, the service and the other (separate) application are both reading/writing the shared data at high speeds on the same machine. The data is basically a list of field-value pairs.
A: 

Plain old RMI is what was used for what you need. Now newer alternatives such as WS are prefered, but maybe the first is enough to you.

Fernando Miguélez