• Post Reply Bookmark Topic Watch Topic
  • New Topic

Streaming objects using threads  RSS feed

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am trying to transfer an object from a client to a server, do some simple computations, and return the object back to the client. But something is wrong, i cannot figure out why this doesn't work.

Code for the client class:



Server class:



And finally, the Loan class:



The problem i get when running this is that the client crash every time. After some testing i've noticed that if i comment out line 81 in the client class (ObjectInputStream), this will prevent the crash. So i would assume the problem lies there. But i get the same code to work when i change it to stream primitive values instead of objects. Any idea what's wrong?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Gibbins wrote:
The problem i get when running this is that the client crash every time. After some testing i've noticed that if i comment out line 81 in the client class (ObjectInputStream), this will prevent the crash.


Please define "crash" in this context.

Tom Gibbins wrote:So i would assume the problem lies there. But i get the same code to work when i change it to stream primitive values instead of objects. Any idea what's wrong?


If you have the option to not serialize objects, I would highly recommend taking that option. Object serialization is not efficient, and for user defined classes, even requires class files on both sides to be at the same version.

Henry
 
Tom Gibbins
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Tom Gibbins wrote:
The problem i get when running this is that the client crash every time. After some testing i've noticed that if i comment out line 81 in the client class (ObjectInputStream), this will prevent the crash.


Please define "crash" in this context.

Tom Gibbins wrote:So i would assume the problem lies there. But i get the same code to work when i change it to stream primitive values instead of objects. Any idea what's wrong?


If you have the option to not serialize objects, I would highly recommend taking that option. Object serialization is not efficient, and for user defined classes, even requires class files on both sides to be at the same version.

Henry


Hi there. The GUI starts to load, but keeps "loading" forever, without displaying any javafx elements. I then have to close it by using windows "Close the program" option. It loads perfectly fine if i comment out line 81 in the client class. I realize this is not the most efficient code transfer-wise, but main purpose here is to gain insight in java object streaming.
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 81 is blocking. Not sure why.

When trying to fix a problem in an application with many layers, I often reassemble the pertinent parts inside a small command line program for debugging purposes. This also helps others help me as I can then post an actual working program (except where it doesn't work).
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move line 81 to just above 65.
81 blocks until data is available.
 
Tom Gibbins
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Move line 81 to just above 65.
81 blocks until data is available.


Perfect, that did the trick!. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!