Uploaded image for project: 'Google Code-in'
  1. Google Code-in
  2. GCI-241

Lazy initialization of static serviceContext should be synchronized in Context.java

    XMLWordPrintable

Details

    • Low

    Description

      This: https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/api/context/Context.java#L247

      And this: https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/api/context/Context.java#L269

      methods should be synchronized.

      Background information:

      In a multi-threaded situation, un-synchronized lazy initialization of non-volatile fields could mean that a second thread has access to a half-initizliaed object while the first thread is still creating it. Allowing such access could cause serious bugs. Instead. the initizliation block should be synchronized or the variable made volatile.
      
      Similarly, updates of such fields should also be synchronized.

       

      You will need to test by running an OpenMRS instance with these changes to see if it still runs to completion without freezing. That is to the point where you can log in.

      Gliffy Diagrams

        Attachments

          Activity

            People

              jwnasambu Juliet Wamalwa
              dkayiwa Daniel Kayiwa
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Time Spent - 15 minutes Remaining Estimate - 3 hours
                  3h
                  Logged:
                  Time Spent - 15 minutes Remaining Estimate - 3 hours
                  15m