[concurrency-interest] static initialization and thread safety

Bobrowski, Maciej Maciej.Bobrowski at morganstanley.com
Tue Apr 4 10:49:34 EDT 2017

I was wondering what guarantees there are about non-final fields initialized as part of class initialization. Let's consider

Class Point{

    int x, y;

    public Point(int x, int y) {
         this.x = x;
         this.y = y;

Class Init{
    public static Point p = new Point(1,2)
    public static Point p2;

    static {
        p2 = new Point(3 , 4)
        p2.x = 10


If I have multiple threads trying to read p and p2, would ALL threads wait until those objects are fully constructed and assigned to corresponding fields (like in final fields case) due to initial;ization semantics, or is that not the case?



NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers  If you cannot access these links, please notify us by reply message and we will send the contents to you. By communicating with Morgan Stanley you consent to the foregoing and to the voice recording of conversations with personnel of Morgan Stanley.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170404/b8ee952c/attachment.html>

More information about the Concurrency-interest mailing list