Link to home
Start Free TrialLog in
Avatar of rahul_asanikar
rahul_asanikar

asked on

Servlet: Slow transfer of serialized data over network

Hi,

I wish to save the data from my Applet to the server through Servlet.
I am serializing the vector data over the network and sending through URLConnection.
But the readObject() method on the remote servlet is very slow in reading the data.
It takes over 4 minutes for the same.
However on the local machine, similar method just takes 2-3 seconds.

Can someone please help me so that my serialized data transfer to Servlet is fast.
I intend to do the job in not more than few seconds.
Thanks in advance.

Best regards,
Rahul
Avatar of Mayank S
Mayank S
Flag of India image

What is the data that you are storing in the Vector? Try using an ArrayList instead though I doubt if it will affect serialization/ deserialization speed.
Avatar of Ajay-Singh
Ajay-Singh

Use BufferedInputStream to read the data.
what kind of data it is? if its all primitive types ( string, integer etc).. you might be able to send them thru on plain HTTP protocol
Avatar of rahul_asanikar

ASKER

I am having an ImageIcon object (the image to be saved on server) and a String (image name) in the vector.
Unfortunately, ArrayList and BufferedInputStream don't seem to help much.
Guess if it vector data is compressed, the amount of data to be transferred would decrease.
Do give your opinion in this regard or any other options available.
Did you try BufferedInputStream?
What objects are you passing in the Vector?
I tried BufferedInputStream to read the serialized data on servlet, but could not find any benefit.
The data in my vector is an image (ImageIcon object) and a String (the image name).
The image is supposed to be saved on the server with the given name through servlet.
The image save time has become a performance bottleneck!!
So the problem needs to be quickly solved.
ASKER CERTIFIED SOLUTION
Avatar of Ajay-Singh
Ajay-Singh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try serializing the object to bytes and sending the byte[] array in chunks using a BufferedOutputStream and read on the other end using BufferedInputStream - similar to what Ajay had said earlier.
Also, if there are users waiting for this operation to be completed before they can do something else, maybe do this in another thread.
My Applet gives security exception when tried to implement XMLEncoder.
Basically, the security policies of the Applet prevents the operation.

Just wish to add that my ImageIcon object is derived from an Image object that is created on the fly.
The image is created based on what the user draws using the Applet.
Hence, would prefer to wait for the image save in the same thread as the user should not be allowed to update the image contents during the process.

Please let me know if any other solution would help me save the image on server in just few seconds.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial