729 questions
0
votes
3
answers
206
views
Singleton using Lazy<T> vs Singleton using static field initializer
I am storing some settings for my application in a JSON file located alongside the application .exe. I want to load these settings only once, lazily, the first time one of them is needed. So for ...
0
votes
2
answers
141
views
How can I force iterator blocks to validate parameters before packing up and returning as a continuation?
Situation: A method that validates its arguments and returns an iterator;
public static IEnumerable<double> Range(double startingValue, double step, int count)
{
// I would really like this ...
1
vote
1
answer
137
views
Hibernate Lazy Loading Interceptor returning NULL
I have the following entities:
class A {
@Id
String aId;
@OneToMany(fetch = FetchType.LAZY)
List<B> bsOfA
@OneToMany(fetch = FetchType.LAZY)
List<C> csOfA
public A(String ...
1
vote
3
answers
297
views
LazyLock not taking closure?
I have a struct with a LazyLock and a constructor function that helps set it.
struct X {
x: LazyLock<ComplexType>,
}
impl X {
pub fn new(x_factory: ComplexTypeFactory) -> Self {
...
0
votes
0
answers
70
views
Could not write JSON: failed to lazily initialize a collection ...Project.issues: no Session
Project Name: Project-Manager
I am trying to implement a service class which would fetch all the projects or single projects from the DB by id but in both the cases I am getting this lazy ...
2
votes
1
answer
529
views
Naming convention for private properties with backing field in C#
Is there an official naming convention for private properties?
I use them for lazy initialization of expensive fields:
private string _veryExpensive;
private string VeryExpensive => _veryExpensive ?...
0
votes
1
answer
55
views
What are Lazy Properties good for? What's their aim?
What is the purpose, respectively the aim, of a lazy property?
Kotlin-language documentation: https://kotlinlang.org/docs/delegated-properties.html#lazy-properties
Saving memory? Or is it something ...
2
votes
1
answer
58
views
Scala initialization order object vs. val
In the following program an object is reported as null, even though it is clearly initialized.
class MyClass()
class MyOtherClass(c: MyClass)
object Foo {
val myClass = new MyClass()
object ...
0
votes
1
answer
71
views
Spring boot: dependency cycle between beans could not be broken
I am working on creating an Airline website using Spring Boot. I have a Seat class and a Flight class which represent tables in the database. The idea is that whenever a flight is added, seats for the ...
0
votes
1
answer
45
views
TransientObjectException during commit when adding entity to an uninitialized lazy collection in Hibernate
Assume, we have two simple entities Parent and Child like the following:
@Entity
public class Parent extends BaseEntity {
private String content;
@OneToMany(mappedBy = "parent", ...
0
votes
1
answer
49
views
Instantiate lazy val which depends on runtime parameter in concurrent env
I need to instantiate MyHttpClient as Singleton. MyHttpClient is used by multiple threads.
Solution below works, but it's ugly and should have issue with endpoint, I just didn't hit it yet.
endpoint ...
-2
votes
1
answer
392
views
Selenium WebDriver PageFactory Webelement initialization
I have more than 500 web-elements in a webpage. If I use Page Object Model with PageFactory.initElements() in selenium it will initialize all the elements once the object is created.
Lets says I am ...
1
vote
0
answers
143
views
Issue with Re-rendering of Horizontal ScrollView Inside Vertical ScrollView in SwiftUI
I am encountering an issue with re-rendering of a horizontal ScrollView inside a vertical ScrollView in SwiftUI. The vertical ScrollView contains multiple horizontal ScrollViews, each displaying a ...
1
vote
1
answer
259
views
Using AtomicReference for lazy init
can the lazy init be done safely this way? We had a dispute where a colleague was claming for some first threads it could fail and they would see the null value.
public class TestAtomicReference {
...
0
votes
1
answer
298
views
How to Initialize Redux Store asynchronously?
I have a Next.js Application and for State Management I am using Redux Toolkit. Now, to maintain authentication status in frontend side, I need to take the existing token and send it to backend for ...
1
vote
1
answer
678
views
Am I using in a wrong way async lazy initialization?
I have a view model with 2 collections, that takes the data from database. For example countries and type of VAT.
I would like to defer the initialization of this collections until I will, becauase if ...
0
votes
0
answers
40
views
Fortran: Initialization of allocatable array with another array [duplicate]
I read a Fortran code :
program t
real :: x(5) =[1.,-2.,3.,-4.,5.]
real,allocatable :: y(:)
y = x
...
For me the normal way is
allocate(y,source=x)
I'm surprised that it works, both ...
1
vote
2
answers
207
views
Racy Single-Check Idiom with Intermediate Result
The racy single-check idiom is a technique for lazy initialization without synchronization or volatile. It can be used when initialization is allowed to be performed concurrently by multiple threads, ...
2
votes
0
answers
146
views
Faster loading of R Markdown html document
Dear StackOverflow members,
I am creating big html documents using R Markdown. These documents contain 200 till 300 charts generated using ggplotly. The creation/knitting of these files works well. ...
-2
votes
1
answer
120
views
Use object guarded by Mutex
I want to implement a lazy static reqwest::ClientBuilder. NB this is for a utilities module, so I have a feeling it'd be difficult to avoid using a static in this case. I want to construct it once, ...
-1
votes
3
answers
294
views
let `lazy` recalculate when value changed
I would like to have something like Android Compose's remember(key) { init } in plain JVM Kotlin. So some sort of Lazy delegate but on every access it calls a key function and if its return value ...
2
votes
1
answer
6k
views
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: in Spring boot
In our case there are two entities User and UserRole and relationship between those two entity are one to many relationship. We perform some operation like we get the user data using Hibernate and ...
1
vote
0
answers
68
views
Convert Realm objects to non-third-party objects in a lazy way: Results<Item> to [Item]
I'm trying to map Realm Persisted Objects to another Type for separation of concerns.
I have something like a protocol repository retrieving an array of items: [Item]
I've one implementation of this ...
0
votes
1
answer
1k
views
Lazy initialisation of lazy_static?
I've already had some success with lazy_static:
static ref WORD_COUNT_REPORTING_STEP_MUTEX: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
static ref INDEX_NAME: RwLock<String> = ...
0
votes
0
answers
451
views
Why is mockkConstructor() not working on the every block?
I'm trying to mock a constructor of a class that is a lazy variable of the class I'm testing:
private val manager by lazy {
manager(Data(ID_ADMIN, MANAGER_CODE), context)
}
I have the mockk() ...
0
votes
1
answer
297
views
How to create lazy initialization (proxy) wrapper in python?
Given an expensive to initialize object and 2 consumers:
class A:
def __init__():
time.sleep(42)
self.foo = 1
def func1(obj: A):
pass
def func2(obj: A):
print(A.foo)
How to create a ...
2
votes
1
answer
1k
views
the Difference between Eager Initialization and Lazy Initialization in Singleton Pattern
I find two different ways to implement a singleton pattern, they are Lazy Initialization and Eager Initialization. and the code is:
public class EagerSingleton {
private static final ...
1
vote
0
answers
74
views
How can I implement a thread-safe lazy-initialized singleton in C# without using the `Lazy<T>` class? [duplicate]
I've been reading about the Singleton pattern in C# and how thread safety can be a concern, especially when it comes to lazy initialization. I'm aware of the Lazy<T> class which can be used to ...
0
votes
1
answer
959
views
Spring lazy initialization applies to imported configuration classes
When I enable spring.main.lazy-initialization=true then Spring does not instantiate configuration classes referenced by @Import.
I have to explicitly @Autowire them into entrypoint to get them picked ...
1
vote
0
answers
299
views
How to initialize a lazy variable before rendering using provider?
I want to initialize a variable before getting to the GoRouter routes.
This authenticated below is the variable I want to initialize:
class AuthProvider with ChangeNotifier {
late bool? ...
0
votes
2
answers
1k
views
CompletableFeature: Failed to Lazily Initialize a Collection X:, could not initialize proxy - no Session
My code has several JPA repository method call. I fetch data and aggregate it. But I want to do that in an asynchronous way. So, I am trying to use CompletableFeature. But I am getting the below error:...
0
votes
2
answers
696
views
Java singleton lazy initialization. Volatile vs synchronized method
Why do we need to add volatile to field to prevent invalid data retrieval? Can't we do the same thing by adding synchronized to method declaration instead of to a block of code?
public class ...
2
votes
1
answer
3k
views
not able to get mutable reference to the underlying OnceLock data
I'm trying to get a mutable reference to the underlying data of OnceLock using get_mut() method, but getting error
mod OL {
use std::sync::OnceLock;
static CELL: OnceLock<i32> = ...
1
vote
1
answer
443
views
Hibernate 5.3+ using hibernateLazyInitializer causes javax.persistence.EntityNotFoundException: Unable to find entity.Person
Having a problem with upgrading hibernate to 5.3+ with the method calling getHibernateLazyInitializer().getIdentifier() on a HibernateProxy which is loaded with AuditedReader from hibernate envers.
...
3
votes
0
answers
100
views
R Shiny - lazy load out-of-view plots
When making an app with a large number of plots, it takes quite a while to load them. The issue is that all the plots on a page start rendering at the same time, even though a good number of them are ...
3
votes
2
answers
5k
views
Provide lazy injection using dagger hilt 2.42
Dagger hilt 2.42
I am trying to provide this class using lazy dagger injection.
class AlgoliaAnalyticsProvider @Inject constructor(
private val clientInsights: Lazy<ClientInsights>,
...
0
votes
1
answer
175
views
Swift can lazy, get and didSet together
Can we do get and didSet together with lazy keyword. I have an array it fetch data from database (get) and another thing when that array will modify i will call delegate to reload data in didSet.
Its ...
0
votes
1
answer
182
views
Lazy var initialization error "Cannot use mutating getter on immutable value"
I tried two ways of initializing a lazy var, one works, the other gets a compiler error.
OK: var maxDiscount = MaxDiscount(); maxDiscount.maxDiscountPercent
ERROR: MaxDiscount().maxDiscountPercent
If ...
-3
votes
2
answers
2k
views
How to do lazy instantiation in python?
in the class below variables with str type are used but without declaring value
from abc import ABC
class User(ABC):
first_name: str
last_name: str
is this lazy instantiation?
0
votes
0
answers
85
views
TypeError: str.replace is not a function when using proxy object in TypeScript
I have a TypeScript class that extends an abstract class called Lazy. The Lazy class uses a proxy object to get and set properties dynamically. Here is the code:
abstract class Lazy<T> {
...
1
vote
2
answers
129
views
Whats the difference of using ={}() with a lazy property or just =
There are two different ways of using the lazy property syntax and I fail to see the difference between them:
//1
lazy var a = { "hello" }()
//2
lazy var b = "hello"
In other ...
4
votes
2
answers
2k
views
Using @Lazy with @RequiredArgsConstructor
...
@RequiredArgsContructor(onConstructor_ = {@Lazy})
Class A{
private final B b;
@Lazy
private final C c;
}
Class A{
private final B b;
private final C c;
A(B b,@Lazy C c){
this.b = ...
1
vote
1
answer
178
views
Hibernate LazyInitialization exception in console Spring Boot with an open session
I'm not sure if anyone has experienced this particular twist of the LazyInitialization issue.
I have a console Spring Boot application (so: no views - everything basically happens within a single ...
0
votes
0
answers
327
views
Unable to locate current JTA transaction during integration of Jboss Resteasy and Spring
Can any one help me with correct approach to integrate Resteasy and Spring with AOP declartive configuration for JTA transaction.
The configuration is as per below,
Project structure:
com.example.dao
...
0
votes
0
answers
116
views
hibernate criteria query for one to many relationship with error when selecting children values
I have an error when selecting the children values of the installer entity which name it infoRges
installer entity:
@Entity
@Table(name = "installer")
public class Installer ...
1
vote
2
answers
1k
views
Global variable concurrent use for write-once read-many usecase
I want to use a global variable. During first access to read it, I want to write to this variable using an API. For any subsequent access to read it, it should not require locks.
This is the ...
1
vote
0
answers
432
views
Using `std::call_once` for lazy initialization
Briefly, I have a class that lazily initializes one of its data members and I'd like to figure out the best way to do this in a multithreaded environment.
In more detail, my class currently looks ...
0
votes
2
answers
129
views
How to resolve all async deferred nested values of a lazy initializable data structure?
I'm looking for vocabulary or for a library that supports the following behaviour:
Imagine a Javascript object like the following one:
const foo = {
id: 1,
name: 'Some String value',
supplier: ...
0
votes
1
answer
350
views
Lazy tag is not working as supposed to be - Lazy is not lazy - initialized before used / called
I am intending to use lazy initialization with a .NET core 6 WPF application with the following.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
...
0
votes
1
answer
524
views
Hibernate - how to fetch @OneToMany lazy collection inside another @OneToMany lazy collection without N+1
I have something like this
Entity1
@Id
String id1;
@OneToMany(Fetch = LAZY)
List<Entity2> list1;
...
Entity2
@Id
String id2;
@OneToMany(Fetch = LAZY)
List<Entity3> list2;
...
Entity3
@Id
...