There are five libraries in our system. viz
01) communikator
02) FM
03) NM
04) UM
05) booter
06) application
Each of these libraries has a defined API - a Facade.
Libraries communicate with each-other thru their facade only.
FM is dependent on communikator.i.e.FM calls methods in communikator facade only.
NM is dependent on FM and communikator.i.e. calls methods in communikator and FM facades only.
UM is dependent on NM,FM and communikator.i.e. calls methods in communikator,FM and NM facades only.
booter is dependent on jars 1 thru 4.i.e. calls methods in communikator,FM,NM and UM facades only.
application is dependent on jars 1 thru 5.i.e. calls methods in communikator,FM,NM,UM and booter facades.
communikator spawns three daemon threads.viz.
* message
thread - receive messages from server
* trap thread - receive traps from server
* connection manager- manage connection between communikator and server
Each of the these threads may traverse or land in any of the other five libraries.
application may spawn multiples threads.
None of the libraries are thread-safe and the entire application has been running without any problem so far.
We understand that threads may inter-leave and the libraries have to be synchronized.
This is where the dilemma is.
There are two ways to synchronize the libraries:
a) Traverse the flow of each of the thread and find where they inter-leave.
Synchronize only blocks/methods that occur where threads interleave and may lead to corruption(We have a fairly good understanding o\f how data may be corrupted)
In this approach we depend on the behvaiour of the system and synchronize only required blocks/methods
b) Ignore thread flow and synchronize all blocks/methods that may be corrupted in a multi-threaded environment.
In this approach we dont depend on the behvaiour of the systeam and synchronize all blocks/methods that contain vulnerable data.
Approach (b) is fairly straight-forward. Identifying data that will be corrupted by-theory is easy. But we may end up synchronizing \blocks where threads may never inter-leave. We end-up locking and unlocking resources un-necessarily.
Approach (a) is not easy. Traversing each thread spawned by communikator and application is enormous effort. Many a time,we dont eve\n konw how-many threads will be spawned by the application.
Which approach to choose?
Is there a tool to identify and highlight blocks where threads interleave?
Thanks in advance.