Piped stream help.

A

Andrew Tucker

Hi Everyone,
I have two servlets that both need access to a data file. I would like to
have a 'driver' program that takes care of writing / reading objects to the
data file and i would like the driver program to be able to communicate
objects to each servlet. Can i do this w/ pipedinput / output streams? I do
not understand how i can reference a piped output stream in one object from
another!

TIA, Andrew.
 
K

Knute Johnson

Andrew said:
Hi Everyone,
I have two servlets that both need access to a data file. I would like to
have a 'driver' program that takes care of writing / reading objects to the
data file and i would like the driver program to be able to communicate
objects to each servlet. Can i do this w/ pipedinput / output streams? I do
not understand how i can reference a piped output stream in one object from
another!

TIA, Andrew.

Piped streams are used to communicate between threads, not between VMs.
Reference them with global variables.
 
R

Roedy Green

I have two servlets that both need access to a data file. I would like to
have a 'driver' program that takes care of writing / reading objects to the
data file and i would like the driver program to be able to communicate
objects to each servlet. Can i do this w/ pipedinput / output streams? I do
not understand how i can reference a piped output stream in one object from
another!

If they are running in the same JVM you can use pipes. If they are in
different JVMs you need to use Sockets. In either case ask the file
i/o amanuensis for how. See http://mindprod.com/fileio.html
 
H

Harald Hein

Andrew Tucker said:
I have two servlets that both need access to a data file. I would
like to have a 'driver' program that takes care of writing /
reading objects to the data file and i would like the driver
program to be able to communicate objects to each servlet. Can i
do this w/ pipedinput / output streams?

Yes, if you are in the same VM. But in this case you could also use a
simpler architecture. Since you claim that your "driver" already
converts file data from/to objects, a simple mechanism to pass the
object references around would do.

If you use a piped stream, you would have to serialize the objects
from/to the driver which is unnecessary overhead. Piped streams are
nice to send raw data between two threads, but are otherwise not
extremely useful.

You could e.g. use some queue data structure for passing the object
references around, or you could provide your "driver" with a simple api
like:

public synchronized YourDataClass read(String key);
public synchronized void write(String key, YourDataClass data);

Both of your servelets get a reference to the driver object and use
this API.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top