Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads and Constructors  RSS feed

 
Jens Mayer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this is a dumb question, but...

look at this snippet:

Let's say two Threads are using the constants constA and constB concurrently. First time the class is loaded, both constants will be initialized. Do I have to synchronize the code in the constructor or is "class-loading" always automatically synchronized (because the class loader will load the class exactly one time) ?

thanks in advance!

Jens
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No synchronization is required. A class will be initialized exactly once.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!