lazy-initialization

How to test spring batch job within @Transactional SpringBootTest test case?

早过忘川 提交于 2021-02-11 14:46:25
问题 I just can't seem to win today... Is there a way to read from a OneToMany relationship in a Spock SpringBootTest integration test, without annotating the test as @Transactional or adding the unrealistic spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true ? OR, is there a way to launch a Spring-Batch Job from within a @Transactional test case? Let me elaborate... I'm trying to get a simple Spring Boot Integration test working for my Spring Batch reporting process, which reads from

Is using Lazy<T> bad for performance?

为君一笑 提交于 2021-02-07 05:28:25
问题 Recently I was having some issues with a singelton class that was lazy initializing a dictionary where a second thread would try to use it before it had actually been populated. So I implemented the variable initialization through the Lazy<T> class. Here is my code: private static Dictionary<string, string> GroupDefaults { get { return mGroupDefaults.Value; } } private static Lazy<Dictionary<string, string>> mGroupDefaults = new Lazy<Dictionary<string,string>>(delegate { Dictionary<string,

What advantages does Lazy<T> offer over standard lazy instantiation?

故事扮演 提交于 2021-02-04 17:08:00
问题 Consider this example, it shows two possible ways of lazy initialization. Except for being thread-safe, are there any specific advantates of using Lazy<T> here? class Customer { private decimal? _balance2; private static decimal GetBalanceOverNetwork() { //lengthy network operations Thread.Sleep(2000); return 99.9M; } public decimal? GetBalance2Lazily() { return _balance2 ?? (_balance2 = GetBalanceOverNetwork()); } private readonly Lazy<decimal> _balance1 = new Lazy<decimal>

What advantages does Lazy<T> offer over standard lazy instantiation?

有些话、适合烂在心里 提交于 2021-02-04 17:07:34
问题 Consider this example, it shows two possible ways of lazy initialization. Except for being thread-safe, are there any specific advantates of using Lazy<T> here? class Customer { private decimal? _balance2; private static decimal GetBalanceOverNetwork() { //lengthy network operations Thread.Sleep(2000); return 99.9M; } public decimal? GetBalance2Lazily() { return _balance2 ?? (_balance2 = GetBalanceOverNetwork()); } private readonly Lazy<decimal> _balance1 = new Lazy<decimal>

hibernate.enable_lazy_load_no_trans is not working

那年仲夏 提交于 2021-01-20 07:45:31
问题 I'm using JPA2.1 and hibernate 4.3.8 and i have configured the presistence.xml to allow lazy loading i have added <property name="hibernate.enable_lazy_load_no_trans" value="true" /> into properties section but i'm still getting LazyInitializtionException, what is the problem ? 回答1: The hibernate.enable_lazy_load_no_trans is an anti-pattern and you should never use it because a database connection is needed for every lazy association that is fetched outside of the initial Persistence Context,

Why enum singleton is lazy?

杀马特。学长 韩版系。学妹 提交于 2020-11-29 11:11:36
问题 I saw answers like these, tried to clarify via comments, and was unsatisfied by examples here. Maybe it's time for this specific question... Why enum singleton implementation is called lazy ? public enum EnumLazySingleton { INSTANCE; EnumLazySingleton() { System.out.println("constructing: " + this); } public static void touchClass() {} } How it is different from eager implementation? public class BasicEagerSingleton { private static final BasicEagerSingleton instance = new BasicEagerSingleton

Why enum singleton is lazy?

生来就可爱ヽ(ⅴ<●) 提交于 2020-11-29 11:09:34
问题 I saw answers like these, tried to clarify via comments, and was unsatisfied by examples here. Maybe it's time for this specific question... Why enum singleton implementation is called lazy ? public enum EnumLazySingleton { INSTANCE; EnumLazySingleton() { System.out.println("constructing: " + this); } public static void touchClass() {} } How it is different from eager implementation? public class BasicEagerSingleton { private static final BasicEagerSingleton instance = new BasicEagerSingleton

How to use System.Lazy with Setter to Lazy Initialization of List in POCO Entities?

冷暖自知 提交于 2020-02-26 11:31:15
问题 I want to use System.Lazy to Lazy Initialization of my List in my Entites: public class Questionary { private Lazy<List<Question>> _questions = new Lazy<List<Question>>(() => new List<Question>()); public IList<Question> Questions { get { return _questions.Value; } set { _questions.Value = value; } } } The problem is on my SETTER, get this error: The property ' System.Lazy<T>.Value ' has no setter If i want to do MyInstance.Questions = new List<Question> { ... } ? How do I proceed? Update: I

Thread safe lazy construction of a singleton in C++

被刻印的时光 ゝ 提交于 2020-01-18 11:44:14
问题 Is there a way to implement a singleton object in C++ that is: Lazily constructed in a thread safe manner (two threads might simultaneously be the first user of the singleton - it should still only be constructed once). Doesn't rely on static variables being constructed beforehand (so the singleton object is itself safe to use during the construction of static variables). (I don't know my C++ well enough, but is it the case that integral and constant static variables are initialized before

Thread safe lazy construction of a singleton in C++

白昼怎懂夜的黑 提交于 2020-01-18 11:44:09
问题 Is there a way to implement a singleton object in C++ that is: Lazily constructed in a thread safe manner (two threads might simultaneously be the first user of the singleton - it should still only be constructed once). Doesn't rely on static variables being constructed beforehand (so the singleton object is itself safe to use during the construction of static variables). (I don't know my C++ well enough, but is it the case that integral and constant static variables are initialized before