27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Distributed systems<br />

serializable? In other words, make them private:<br />

class Foo implements Serializable {<br />

private Bar bar;<br />

}<br />

Do you *need* to maintain the state of the 'bar' variable when serializing/deserializing<br />

Foo? If not, simply declare 'bar' as 'transient' and it will be ingored during<br />

serialization.<br />

RMI versus Socket communication<br />

I wish to get <strong>Java</strong> talking to C++ across a network.<br />

Does anyone have any thoughts in terms of performance, ease of development etc.<br />

in :<br />

Wrapping the C++ side with JNI and using RMI for the communications.<br />

versus<br />

Writing sockets code and communicating via http?<br />

Answer: It depends of what kind of application you're writing but l think about<br />

the following :<br />

- with RMI you can have remote REFERENCE instead of having to transfer all the<br />

object through the network. The object has just to implement Remote. So it spare<br />

bandwith and is good for performance. This is impossible to do if you do through a<br />

socket connection, you've to send the all object.<br />

- You've not to take in charge the serialization (which could be not so easy<br />

depending of your object structure), neither the connections, etc... All of that is taken<br />

in charge by RMI.<br />

- the performance are GOOD (even a bit more than that)<br />

three good points to use RMI, isn't it?<br />

The difficulty added by RMI is the configuration of both client and server (distribution<br />

of stubs, rmiregistry, what's happen if firewall). Depending of the environment all of<br />

that can be either easy or complicate.<br />

But once that all of that is in place you can extend your application<br />

easily, so it's much more flexible and scalable.<br />

If your needs are small perhaps that you could do your own connection system (but<br />

for me it's less scalable and more bandwith consuming and so less performant).<br />

--<br />

François Malgrève<br />

Answer2: I have done both. If your communication scenarios are diverse and could<br />

keep changing, using a remote technology like RMI can help. If the operations are<br />

few and/or not likely to change you can save the JNI complexity. Not that it is really<br />

hard it just can be fun keeping the JNI code in sinc with the C++ code.<br />

--<br />

Bret Hansen<br />

Q: I need to communicate some data (string) from a <strong>Java</strong> Applet to an other ASP<br />

page in the same frameset. I would like to avoid a server roundtrip and do it all with<br />

<strong>Java</strong>Script if possible.<br />

Therefore I would like to call some javascript from a <strong>Java</strong> Applet. It looks like it is not<br />

file:///F|/350_t/350_tips/distributed_systems.htm (2 of 4) [2002-02-27 21:18:03]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!