public static void main(String[] args) throws Exception { // Always get the Guice injector from Governator LifecycleInjector lifecycleInjector = LifecycleInjector.builder().withModules(new ExampleModule()).build(); Injector injector = lifecycleInjector.createInjector(); LifecycleManager manager = injector.getInstance(LifecycleManager.class); // Always start the Lifecycle Manager manager.start(); long objectsToCreate = 10000; // Test creating objects without @JsonProperty annotations ExamplePojoWithoutAnnotationsFactory factory2 = injector.getInstance(ExamplePojoWithoutAnnotationsFactory.class); long start = System.currentTimeMillis(); for (int i = 0; i < objectsToCreate; i++) { factory2.create(); } long end = System.currentTimeMillis(); System.out.println("Created " + objectsToCreate + " objects in " + (end - start) + "ms"); // Test creating objects with @JsonProperty annotations ExamplePojoWithAnnotationsFactory factory1 = injector.getInstance(ExamplePojoWithAnnotationsFactory.class); start = System.currentTimeMillis(); for (int i = 0; i < objectsToCreate; i++) { factory1.create(); } end = System.currentTimeMillis(); System.out.println( "Created " + objectsToCreate + " objects with annotations in " + (end - start) + "ms"); // Always close the Lifecycle Manager at app end manager.close(); }
private Injector createInjector(final Properties properties) { injector = LifecycleInjector.builder() .withBootstrapModule( new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder .bindConfigurationProvider() .toInstance(new PropertiesConfigurationProvider(properties)); } }) .withModules(new SuroClientModule()) .createInjector(); LifecycleManager manager = injector.getInstance(LifecycleManager.class); try { manager.start(); } catch (Exception e) { throw new RuntimeException( "LifecycleManager cannot start with an exception: " + e.getMessage(), e); } return injector; }