• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Clarification required on synchronized block

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two list a, b. One thread is adding the data into the list and start the timer if the timer is not already started.



Another thread is a timer Task thread that will wake up for every 5 secs to read the list and process as follows.



Could any clarify my questions in the comments of the code. if my logic is wrong please provide the better way to implement to avoid synchronization issue.
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to 1 is yes but I think you have more problems than that.

I'd simplify this down to synchronisation that covered A & B for reads and writes, with a single object to signal between threads and then optimise it later if you have to, you seem to be struggling a bit. If your not 100% confident simple is always best.
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must synchronize on both lists before looking at their combined
size. Otherwise, one of the add() methods could loose an object while
MyTask thinks the lists are empty. To process the non-empty lists, you
can synchronize separately again if you wish.
Jim ... ...
 
shan raj
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your suggestions.

Chris Hurst ,

Could you provide sample program or tutorial to use the single object to signal between the thread.


I will also try "Jim Hoglund" suggestion given in the previous posts.

Regards
Shan
 
There is no "i" in denial. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic