• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Streaming objects using threads

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic