Is it possible to implement a multi-threaded class loader in Java? In a meta-driven framework I need to load several hundreds of classes in advance, ie, not as lazily as the system classloader. In order to accelerate this, I would like to better utilize current multi-core CPUs. Before I dive into that, I would be interested if somebody already has some experience on this issue or if it is possibly totally clear that perhaps defineClass()
is the bottleneck in this case.
Thanks Andre
Multithreading is useful when a thread is awaiting a response from another computer or piece of hardware. While one thread is blocked while performing the task, other threads can take advantage of the otherwise unburdened computer.
With a custom classloader you can add behaviour to the loaded classes before they are passed over to the running application. Show activity on this post. Java class loaders do pretty much what the name suggests: load classes into memory so that they can be used.
Java uses ClassLoader implicitly when you use new , import keyword, the jvm will use the current class's classloader to load the dependent classes, so you can use the custom classloader to load a bootstrap class explicitly by using classloader.
I believe currently you will hit an exclusive lock. In JDK7, class loaders will be able to mark themselves as being parallel-capable.
As ever, I suggest possibly doing some back-of-envelope calculations and then suck-it-and-see.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With