• 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

my thread and synchronized

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a threadded server application.

Once my server accepts a connection, a thread is started to work on the client data, while the server returns to accept futher connections.

This is working pretty well...

until yesterday, that is.

I needed to modify my "worker" thread. It now has included a class that is not threaded and needs to invoke one of that classes non-threadded methods.

Something like this:


Now the problem I'm seeing is that myOtherCLass.doSomeWork is being inundated with "clientData" from the multitude of worker threads.

I thought that all I needed to do was to modify the doSomeWork method
from this:



to this:



But this has had no affect.

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


Is there any particular reason why you care if the static method is being invoked by many threads?. As long as the method is operating on the variables local to that method, it should be fine. Do you feel that the method is not thread safe and hence you want to make it synchronized?

I mean the fact that the method is being accessed by multiple threads simultaneously s'dn't bother you as long as it is thread safe.
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jefff willis:



You must keep in mind that local variables are thread safe, while static and instance fields are not.

./pope
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doSomeWork() will update some statistics on the screen.

Depending on which thread invokes doSomeWork(), different stats, and different graphics are updated on a panel.

The problem has been solved since I posted my original note. I was so convinced that the porblem had to deal with synchronizing my method that I overlooked proplems elsewhere in my code.

Thanks, for the input.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic