Comments
@saturnism
In this case, the initialization of See for example https://www.oracle.com/technical-resources/articles/javase/bloch-effective-08-qa.html. Or is there something else here that I'm missing? |
good call on the exception. it is quite a bit of code to show how to use spanner in a function. does it matter whether it's checks for The current code feels like that it will:
Would it make sense for Lastly, would, static initialization work in the class, or IODH? static init exceptions can also be caught if the init happens in a static block. |
Friendly ping on this issue to see what the next steps are. @olavloite, do you have any thoughts on the last comment from @saturnism? |
Sorry, this one slipped of my radar.
Yes, that does matter, as
No, if an error occurs during initialization, the initialized flag will be set to true and the error will be remembered. The same error that occurred during initialization will therefore also be thrown the next time My preferred solution would be if we could add something like the Apache commons LazyInitalizer in the core client libraries that we could use for this. I don't think Spanner is the only cloud client that might throw an exception during initialization, and that should therefore also be using a pattern like this. That would significantly reduce the amount of code in this example, but also make it easier for end users to initialize these kinds of clients. |
We have added a |
The Spanner client library now includes a lazy initializer for Spanner instances that can be used with Google Cloud Functions and other libraries that want to create an instance the first time one is needed and reuse this instance for subsequent requests. Fixes #2862
Describe the issue
GCF Java 11 Spanner sample uses Double checked locking. The pattern is known to be broken, should follow the lazy field init example
The text was updated successfully, but these errors were encountered: