• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to control fast updates

 
Arun Bommannavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In class "ParentClass", I create a number of other objects lets say "child_1" through "child_100". ParentClass implements " PropertyChangeListener". So when any child class has data to send back to the ParentClass, it executes firePropertyChange, and since ParentClass has registered itself as a listener, its propertyChange(PropertyChangeEvent evt) gets executed.

Sometimes, I have noticed that when many child_x fire, I tend to loose data. In other words, when child_1 has fired, ParentClass's "propertyChange" starts executing but before it has finished its job, another child lets say child_20 fires. So it appears that whatever task was supposed to have been done when child_1 fires, doesn't get done.

I hope I have explained my problem clearly. I guess, what I like to do is that access to ParentClass's "propertyChange" be not interrupted before it has finished its job.
Could anyone suggest a technique? A simple example would be indeed greatly appreciated.

Regards,
Arun Bommannavar
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I have to assume each child is running in it own thread because if not then nothing will happen until after the property change listeners have completed. Even so if your code is thread safe you should not loose data - as another property firing your property change listener will not interupt the current one.

Please post a code sample.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this does sound like a thread safety issue. If you can confirm for me that this is a multithreaded program, we can move this to our "Threads and Synchronization" forum.
 
Arun Bommannavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, indeed this is multithreaded program.

Regards
Arun
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. So, the first question is, do you know what "synchronized" does, as in



The "synchronized" keyword means (in this context) that no two threads can invoke this method on the same object at the same time; so that if two events arrive one after the other, the second one will have to wait for the first call to complete before the second one begins.

It's not a magic bullet, though -- there's more to it than that. It's a big topic. Here is one page out of many in the Java Tutorial chapter on Threads which discusses the "synchronized" keyword as you'd want to use it here. Take a little time to read up on this stuff, then c'mon back and ask if'n you got any questions.
[ September 27, 2006: Message edited by: Ernest Friedman-Hill ]
 
Arun Bommannavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for advice. I use JBuilder and when I use the wizard to implement PropertyChangeListener it creates method "public void propertyChange(PropertyChangeEvent evt)" and is not with "synchronized". Offcourse I didn't even try adding "synchronized" and see if it compiles, before seeing your advice and it does.

Again, thanks.

Regards,
Arun
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!