• 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

value is not updated in threads

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i wonder why test(arraylist) is differ in every thread...... someone help me ,need solve it by tomorrow!
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kahnkeen,

it is really hard to read your code. Could you go back and edit it to add the code tags? See this link: UseCodeTags. When you are done could you also be more specific. Why do you think the ArrayList is different in each Thread?
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi steve....
this is because when the clients access this server and the server send value(arraylist which is contact the namelist however the value is differ for every thread,the value is not updated) ....can you try to help me?
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value were? On the client? The one on the other side of the socket connection?

If so, then yeah, that is expected. The list you sent is a copy, turned to bits, transferred across a network, then rebuilt on a different computer in a different JVM (at least as far as this part of the code is concerned). It has no relationship to the list on the server anymore: it should be considered a 'snapshot' of the list at the time the connection was made, not a live view. If you want a live view you have to continuously feed the updates to the list to all clients.
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my client side code....
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this statement write the object which is not updated for the client -> clientList.get(i).outputToClient.writeObject(test); on lines 112
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:The value were? On the client? The one on the other side of the socket connection?

If so, then yeah, that is expected. The list you sent is a copy, turned to bits, transferred across a network, then rebuilt on a different computer in a different JVM (at least as far as this part of the code is concerned). It has no relationship to the list on the server anymore: it should be considered a 'snapshot' of the list at the time the connection was made, not a live view. If you want a live view you have to continuously feed the updates to the list to all clients.



i keep keep the list the whenever user send message or new user is joined....but it still remain same....
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
damn it .the problem was solved after i added the reset() for objectoutstream
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kahkean chor wrote:damn it .the problem was solved after i added the reset() for objectoutstream


Excellent! And thank you for posting the answer to the forums.
reply
    Bookmark Topic Watch Topic
  • New Topic