Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * JBoss, Home of Professional Open Source
  * Copyright 2012, Red Hat, Inc., and individual contributors
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
import  edu.umd.cs.findbugs.annotations.SuppressWarnings;

Allows observer methods for container lifecycle events to be resolved upfront while the deployment is waiting for classloader or reflection API.

Jozef Hartinger
    private class PreloadingTask implements Callable<Void> {
        private final Type type;
        public PreloadingTask(Type type) {
            this. = type;
        public Void call() throws Exception {
            return null;
    private final ExecutorService executor;
    private final ObserverNotifier notifier;
    public ContainerLifecycleEventPreloader(int threadPoolSizeObserverNotifier notifier) {
        this. = Executors.newFixedThreadPool(threadPoolSizenew DaemonThreadFactory(new ThreadGroup("weld-preloaders"), "weld-preloader-"));
        this. = notifier;

In multi-threaded environment we often cannot leverage multiple core fully in bootstrap because the deployer threads are often blocked by the reflection API or waiting to get a classloader lock. While waiting for classes to be loaded or reflection metadata to be obtained, we can make use of the idle CPU cores and start resolving container lifecycle event observers (extensions) upfront for those types of events we know we will be firing. Since these resolutions are cached, firing of the lifecycle events will then be very fast.
    @SuppressWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE", justification = "We never need to synchronize with the preloader.")
    void preloadContainerLifecycleEvent(Class<?> eventRawTypeType... typeParameters) {
        .submit(new PreloadingTask(new ParameterizedTypeImpl(eventRawTypetypeParametersnull)));
    void shutdown() {
        if (!.isShutdown()) {
New to GrepCode? Check out our FAQ X