Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import javax.annotation.PostConstruct;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManagerFactory;
@Singleton // Only need one of these
@Lock(LockType.READ) // allow concurrent access by default
@Startup // initialize on startup
public class HappyFunBall {
// Called when the application boots due to @Startup
@PostConstruct
private void init() {
// do your initialization logic
//
}
// Look, Mom! We're safely halting all
// producer methods while we reload the
// configuration. Yay, thread safety.
@Lock(LockType.WRITE)
public void reloadConfiguration() {
init();
}
@Produces
@Happy
public EntityManagerFactory createEntityManagerFactory() {
// build and return the EntityManagerFactory using your configuration
return null;
}
@Produces
@Fun
public EntityManagerFactory createEntityManagerFactory() {
// build and return the EntityManagerFactory using your configuration
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment