Thread-safe cache of one object in java

google collections actually supplies just the thing for just this sort of thing: Supplier Your code would be something like: private Supplier<List<String>> supplier = new Supplier<List<String>>(){ public List<String> get(){ return loadCountryList(); } }; // volatile reference so that changes are published correctly see invalidate() private volatile Supplier<List<String>> memorized = Suppliers.memoize(supplier); public List<String> list(){ return memorized.get(); … Read more

Repository Pattern: how to Lazy Load? or, Should I split this Aggregate?

Am I misinterpreting the intent of the Repository pattern? I’m going to say “yeah”, but know that me and every person I’ve worked with has asked the same thing for the same reason… “You’re not thinking 4th dimensionally, Marty”. Let’s simplify it a little and stick with constructors instead of Create methods first: Editor e … Read more

Hibernate count collection size without initializing

A possible solution other than queries might be mapping children with lazy=”extra” (in XML notation). This way, you can fetch the Parent with whatever query you need, then call parent.getChildren().size() without loading the whole collection (only a SELECT COUNT type query is executed). With annotations, it would be @OneToMany @org.hibernate.annotations.LazyCollection( org.hibernate.annotations.LazyCollectionOption.EXTRA ) private Set<Child> children … Read more

How to solve the “Double-Checked Locking is Broken” Declaration in Java?

Here is the idiom recommended in the Item 71: Use lazy initialization judiciously of Effective Java: If you need to use lazy initialization for performance on an instance field, use the double-check idiom. This idiom avoids the cost of locking when accessing the field after it has been initialized (Item 67). The idea behind the … Read more

Show activity Indicator while loading a lazy loaded Module in Angular 2

You can listen for two router events: RouteConfigLoadStart RouteConfigLoadEnd They fire when a lazy loaded module is being loaded. The advantage of using these over the standard router events such as NavigationStart is that they won’t fire on every route change. Listen to them in your root AppComponent to show / hide your spinner. app.component.ts … Read more

Lazy Loading HTML5 picture element

It’s February 2020 now and I’m pleased to report that Google Chrome, Microsoft Edge (the Chromium-based Edge), and Mozilla Firefox all support the new loading=”lazy” attribute. The only modern browser hold-out is Apple’s Safari (both iOS Safari and macOS Safari) but they’ve recently finished adding it to Safari’s codebase, so I expect it will be … Read more

Lazy module variables–can it be done?

You can’t do it with modules, but you can disguise a class “as if” it was a module, e.g., in itun.py, code…: import sys class _Sneaky(object): def __init__(self): self.download = None @property def DOWNLOAD_PATH(self): if not self.download: self.download = heavyComputations() return self.download def __getattr__(self, name): return globals()[name] # other parts of itun that you WANT … Read more

IntersectionObserver callback firing immediately on page load

That is the default behaviour. When you instantiate an instance of the IntersectionObserver, the callback will be fired. It is recommended to guard against this case. entries.forEach(entry => { if (entry.intersectionRatio > 0) { entry.target.classList.add(‘in-viewport’); } else { entry.target.classList.remove(‘in-viewport’); } }); Also I found this article as well as the docs to be very helpful, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)