André Pareis
André Pareis

Reputation: 1094

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

Upvotes: 7

Views: 3134

Answers (2)

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

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.

Upvotes: 7

There is nothing wrong with having one or more thread loading a class in the background which requires all the classes you need to preload. Do a prototype with an Executor and Callables so you can get some profiling information with jvisualvm.

Upvotes: -1

Related Questions