aspose file tools*
The moose likes Threads and Synchronization and the fly likes value is not updated in threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "value is not updated in threads" Watch "value is not updated in threads" New topic
Author

value is not updated in threads

kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56

i wonder why test(arraylist) is differ in every thread...... someone help me ,need solve it by tomorrow!
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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?


Steve
kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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

Joined: Jan 26, 2013
Posts: 56
this is my client side code....
kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
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

Joined: Jan 26, 2013
Posts: 56
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

Joined: Jan 26, 2013
Posts: 56
damn it .the problem was solved after i added the reset() for objectoutstream
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: value is not updated in threads