New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions - Java Spanner example uses DCL #2862
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. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
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 GoogleCloudPlatform#2862
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: