How alibaba/asyncload works
Project type and purpose
• This is an open-source Java library (“asyncload”) that provides a business-layer asynchronous, parallel loading mechanism.
• It uses bytecode enhancement at runtime to generate proxies, returns lightweight mock objects immediately, and performs the real method calls in a managed thread pool.
File structure
• Top level:
• pom.xml – Maven coordinates and dependencies
• src/main/java/com/alibaba/asyncload – core Java packages
• src/main/resources – sample Spring XML config
• src/test – unit and integration tests under matching package structure
• Core packages under com.alibaba.asyncload:
• config & executor & method match & proxy classes
• impl.*: proxy implementation, service, result, status enums
• impl/annotation: annotation parser, advice classes, thread‐local, handler factory
• impl/pool: thread‐pool, callable, future, named thread factory
• impl/spring: FactoryBean, Interceptor, AutoProxyCreator
• impl/util & helper: reflection helpers, proxy repository, barrier, utils
• Key patterns:
• Bytecode enhancement / dynamic proxy
• Thread-pool executor with Future objects
• Annotation-driven configuration (custom annotations + parser)
• Optional Spring integration layer
README for additional insights
• Describes the problem (I/O blocking), solution approach (async + parallel), and high-level workflow:
1. Generate proxy and mock object via bytecode enhancement
2. Submit real method call into a thread pool
3. Return mock to caller; when real data is accessed later, block until result is ready
Main components
a. Caller (business code)
b. Proxy Generator / Bytecode Enhancer (e.g., Javassist or ASM)
c. AsyncLoadProxy / AsyncLoadEnhanceProxy
d. AsyncLoadExecutor
e. Thread-Pool Module (AsyncLoadThreadPool, NamedThreadFactory)
f. AsyncLoadFuture / AsyncLoadResult / AsyncLoadObject (mock vs. real result wrapper)
g. Annotation Processor (AsyncLoadAnnotationParserFactory, advice classes)
h. Spring Integration (AsyncLoadFactoryBean, AsyncLoadInterceptor, CompositeAutoProxyCreator)
i. Configuration (AsyncLoadConfig, AsyncThreadPoolConfig)
j. Helper modules (ReflectionHelper, ProxyRepository, Utilities)
Relationships and interactions
• Business code invokes a target method → intercepted by Proxy/Interceptor
• Proxy builds a mock AsyncLoadObject and schedules actual call via AsyncLoadExecutor → places AsyncLoadCallable into AsyncLoadThreadPool
• Thread pool worker executes the real method, wraps results in AsyncLoadResult, signals completion (possibly via AsyncLoadBarrier)
• When business code accesses the mock’s data, AsyncLoadFuture.get() blocks until AsyncLoadResult is available
• Annotation Processor scans classes/methods at startup to identify which to proxy
• Spring layer registers FactoryBean and AutoProxyCreator to weave proxies into the application context
Architectural patterns and principles
• Proxy Pattern (dynamic proxy + bytecode enhancement)
• Future / Promise (AsyncLoadFuture)
• Thread Pool Executor (configurable rejection policies, named threads)
• AOP / Advice (annotation-driven method interception)
• Inversion of Control (Spring integration with FactoryBean + CompositeAutoProxyCreator)