I have a class that implements Serializable , and I protect the invariant of this class through a lock object that is of type Object . Can this be transient, or can it have any unwanted side effects?
Serializable
Object
The code:
class MyClass implements Serializable{ private final transient lock = new Object(); .... }
This is great if you recreate an object during de-serialization so that you have something to sync.
In addition, you may have to remove the final modifier .
final
It's up to you to decide if this is a hassle.
An alternative is to use an empty array (even new Object[0] ). Empty arrays are serializable, while new Object() is not.
new Object[0]
new Object()
I'm used to doing:
private final Object lock = new Object[0];
Source: https://habr.com/ru/post/1299157/More articles:Sitecore workflow for specific item fields - sitecoreDetermine screen color depth / monochrome in .NET compact framework 2.0? - .netDeveloping the bootloader assembly - assemblyObject against byte [0] as a lock - javaHandler for a custom attached event - c #Web CMS performance: pages / sec (Joomla, Drupal, Plone, WP) - pythonLike a white label spring beans - javaRotate a directory in Zip with PHP - directoryChange "ToString" for a private class - tostringhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1299162/how-does-cappuccino-manages-to-layout-views-like-in-cocoa&usg=ALkJrhgE_I3Zc1dVB_M-T9_JaUQVGg60HgAll Articles