Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

...

This noncompliant code example consists of an enumeration Day of days and two classes, Diary and DiaryPool. The class Diary uses a ThreadLocal variable to store thread-specific information, such as each thread's current day. The initial value of the current day is Monday, and this can be changed later by using the setDay() method. The class also contains a thread-specific threadSpecificTask() instance method that performs a thread-specific task.

The class DiaryPool consists of two methods doSomething1() and doSomething2() that start one thread each, respectively. The method doSomething1() changes the initial (default) value of the day in the diary to Friday and invokes the threadSpecificTask() method. On the other hand, the method doSomething2() relies on the initial value of the day (Monday) in the diary and invokes the threadSpecificTask() method. The main() method creates one thread using doSomething1() and two more using doSomething2().

...