1
1
1ex2011-03-09 23:47:14
Java
1ex, 2011-03-09 23:47:14

Should ClassLoader be thread-safe? Does it make sense to cache loaded classes?

Java has such a thing as ClassLoader's, but the defineClass() method is not synchronized, as are the findClass() and loadClass() methods, which is strange, since different threads can access these methods at the same time, which is fraught with reloading For example.

Should I make a custom thread-safe loader?
And, as it seems to me, it should be closely related to this: Is it worth making a custom loader cacheable if loading a class is a lengthy process?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romik, 2011-03-10
@romik

No, everything is already done for you.
The loadClass(String name, boolean resolve) method is synchronized.
The second time the same class will not be loaded, so there is no point in manual caching.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question