Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-threaded classloading possible?

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

like image 763
André Pareis Avatar asked Jul 19 '09 16:07

André Pareis


People also ask

Should I multi thread?

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.

What is the use of custom class loader?

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.

What is custom class loader in Java?

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.


1 Answers

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.

like image 74
Tom Hawtin - tackline Avatar answered Oct 30 '22 16:10

Tom Hawtin - tackline