C C T B H P N

Note #3 - Power and Peril of Sharing

Sharing information and resources is one of the most important things our applications do.
There are several types of sharing that are quite common in applications being built today: But the benefits of sharing come with costs and problems. One client may make changes that adversely affect another. Two clients may attempt to concurrently acquire a resouce causing one to block or perhaps corrupting the state of the resource. Proprietary or secret information may be inadvertently disclosed through sharing of resources.

Conclusions for: Power and Peril of Sharing

Your applications will share user information, external information from stored data, resources like streams, files, queues, and memory.
  1. Do the least amount of sharing possible and still provide the application's functionality.
  2. When you allocate shared resources like files, streams, and database locks, release them as soon as you have finished. Your design should strive to make the duration of use as small as possible.
  3. Return shared resources, when you've finished, in the same state you found them, unless every single user agrees that the modifications are intended and expected.
  4. Keep sharing between theads localized and simple as possible. Sharing through carefully constructed thread-safe containers like Blocking Queues makes threaded designs managable.