Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronized access to System.properties  RSS feed

 
Femi Byte
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to write code where I'd like one thread to create a lock on a specific system property so that the thread can modify the value, allow an object it uses to access this value but prevent another thread from accessing this system property until the 1st thread returns. Is this possible, and if so, is it correct to do so?

Thanks in advance.
 
Alan Mehio
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
allow an object it uses to access this value

Basically you want to prevent stale data i.e prevent the concurrent access to a system property value for write/read
The best think you can do is to synchronize or acquire the lock on the Object which access the system value

such as



Let me know your thoughts

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!