lazy-initialization

How to make a CDI bean lazily initialized?

我只是一个虾纸丫 提交于 2019-12-01 03:34:12
问题 I am using Weld implementation of CDI 1.0 and I cannot find way how to make bean lazy like in Spring (using @Lazy or lazy-init in XML). Is there a way how to tell CDI's Injector not to initialize bean on startup? 回答1: No, this isn't possible in CDI. The closest thing you could get would be to create a new InjectionPoint (using an Extension) implementation that gives a proxy and the proxy would initialize everything on the first method invocation. 回答2: See my answer on: http://www.adam-bien

What does Hibernate.initialize do?

陌路散爱 提交于 2019-11-30 17:36:21
What does Hibernate.initialize do? Usually referred documentation talk only about Hibernate.initialize(entity.lazyCollection) Is there any sense in Hibernate.initialize(entity) I would say yes if the Entity has a lazily initialized field e.g. some large BLOB or CLOB data or a lazy one-to-one association. See 20.1.8. in the documentation for the former and 20.1.3 for the latter. See also: 20.1.4. Initializing collections and proxies I agree with Alan Hay, here is my experience, I've had this problem when running the JUNit tests, some of the lazy objects were not loading when trying to load the

Pass parameters to constructor, when initializing a lazy instance

≯℡__Kan透↙ 提交于 2019-11-30 15:53:03
问题 As I know if a variable is declared Lazy , then its constructor is called when we use the Value property. I need to pass some parameters to this Lazy instance but cannot find the correct syntax. This is not my design, I'm using MEF and ExportFactory , it returns me Lazy instances of my parts. My parts have constructors and I need to call these constructors with some parameters. 回答1: MEF doesn't have a built-in way for you to pass constructor parameters to a part when you create it with an

Lazy Var vs Let

若如初见. 提交于 2019-11-30 10:42:36
I want to use Lazy initialization for some of my properties in Swift. My current code looks like this: lazy var fontSize : CGFloat = { if (someCase) { return CGFloat(30) } else { return CGFloat(17) } }() The thing is that once the fontSize is set it will NEVER change. So I wanted to do something like this: lazy let fontSize : CGFloat = { if (someCase) { return CGFloat(30) } else { return CGFloat(17) } }() Which is impossible. Only this works: let fontSize : CGFloat = { if (someCase) { return CGFloat(30) } else { return CGFloat(17) } }() So - I want a property that will be lazy loaded but will

Scala lazy values : performance penalty? Threadsafe? [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 08:37:01
Possible Duplicate: What's the (hidden) cost of lazy val? (Scala) Scala allows the definition of lazy values lazy val maybeUnusedValue = someCostlyInitialization where someCostlyInitialization is evaluated only on the first use of maybeUnusedValue . That is, it is evaluated at most once, and if maybeUnusedValue is never used, it is also never evaluated at all. Is this threadsafe? What are the performance implications of this? If this is to be threadsafe, it has to use some kind of syncronization / use Java volatile in some way. Unfortunately the Scala language specification says nothing about

Kotlin lazy properties and values reset: a resettable lazy delegate

天涯浪子 提交于 2019-11-30 04:41:36
So I use kotlin for android, and when inflating views, I tend to do the following: private val recyclerView by lazy { find<RecyclerView>(R.id.recyclerView) } This method will work. However, there is a case in which it will bug the app. If this is a fragment, and the fragment goes to the backstack, onCreateView will be called again, and the view hierarchy of the fragment will recreated. Which means, the lazy initiated recyclerView will point out to an old view no longer existent. A solution is like this: private lateinit var recyclerView: RecyclerView And initialise all the properties inside

What does Hibernate.initialize do?

送分小仙女□ 提交于 2019-11-30 01:35:29
问题 What does Hibernate.initialize do? Usually referred documentation talk only about Hibernate.initialize(entity.lazyCollection) Is there any sense in Hibernate.initialize(entity) 回答1: I would say yes if the Entity has a lazily initialized field e.g. some large BLOB or CLOB data or a lazy one-to-one association. See 20.1.8. in the documentation for the former and 20.1.3 for the latter. See also: 20.1.4. Initializing collections and proxies 回答2: I agree with Alan Hay, here is my experience, I've

Singleton lazy vs eager instantiation

社会主义新天地 提交于 2019-11-29 20:27:44
If a singleton is implemented as follows, class Singleton { private static Singleton instance = new Singleton(); public static Singleton getInstance() { return instance; } } How is this implementation different from the lazy initialization approach? In this case,the instance will be created when the class is loaded and the class itself is loaded only on the first active use (for example, Singleton.getInstance() not when you declare for instance Singleton singleton = null;) Even with lazy initialization approach, the instance is created on the call to getInstance() Am i missing something here?

C++ different singleton implementations

≡放荡痞女 提交于 2019-11-29 15:52:55
I usually implement the singleton pattern this way : class Singleton { public: virtual ~Singleton() {} static Singleton& GetInstance() { static Singleton instance; return instance; } private: Singleton(); Singleton(const Singleton&); Singleton& operator=(const Singleton&); } Recently, I ran into this implementation, which is slightly different : class Singleton { public: Singleton(); virtual ~Singleton() {} static Singleton& GetInstance() { return instance; } private: Singleton(const Singleton&); Singleton& operator=(const Singleton&); static Singleton instance; } Singleton Singleton::instance

Scala lazy values : performance penalty? Threadsafe? [duplicate]

风格不统一 提交于 2019-11-29 12:05:07
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What's the (hidden) cost of lazy val? (Scala) Scala allows the definition of lazy values lazy val maybeUnusedValue = someCostlyInitialization where someCostlyInitialization is evaluated only on the first use of maybeUnusedValue . That is, it is evaluated at most once, and if maybeUnusedValue is never used, it is also never evaluated at all. Is this threadsafe? What are the performance implications of this? If