Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

value is not updated in threads

 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i wonder why test(arraylist) is differ in every thread...... someone help me ,need solve it by tomorrow!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
this is my client side code....
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
damn it .the problem was solved after i added the reset() for objectoutstream
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic