Skip to main content

All Questions

1 vote
3 answers
176 views

Ensuring run-once behavior in a multi-threaded environment via volatile lambdas?

I'm coding an enum strategy pattern where one of the strategies makes use of an ScheduledExecutor: class ControllerImpl { //... boolean applyStrat(StratParam param) { getStrat().apply(...
walen's user avatar
  • 355
2 votes
1 answer
1k views

Is it a good idea to use a Lazy wrapper type to encapsulate lazy initialization in Java?

In our code base, we have several static or instance members that we would like to initialize lazily. If the initialization cannot yield null, It's easy to implement. Otherwise, one could use an ...
mperktold's user avatar
  • 151
-3 votes
1 answer
2k views

Is it good practice to call service layer through domain object getters?

Tell me anybody, is it good practice to call service layer methods through domain object getters? Let me show you with an example: public class User { private long id; private String name; ...
Artem's user avatar
  • 3
2 votes
1 answer
1k views

Applying initialization-on-demand holder idiom at variable level rather than class

I was looking for the idiomatic way to implement thread-safe lazy initialization for a configuration collection retrieved from the DB inside a Spring bean. I decided to adapt the initialisation-on-...
Adam's user avatar
  • 187
5 votes
4 answers
4k views

What is a good pattern for combined caching and reinitialization?

I have a situation where I have three requirements: Lazy initialization - don't create the collection until asked for it Caching - keep the collection in memory on the object Reinitialization - be ...
Nicole's user avatar
  • 28.2k
10 votes
4 answers
2k views

Is there any reason lazy initialization couldn't be built into Java?

Since I'm working on a server with absolutely no non-persisted state for users, every User-related object we have is rolled out on every request. Consequently I often find myself doing lazy ...
Nicole's user avatar
  • 28.2k