-
We've been using classgraph successfully for several years, thanks for all your work on it. I'm not sure if it's OK to ask such a question here, apologies if it's not, I was just looking for some advice. We scan the classpath once on startup, in order just to generate a list of classnames… these then indexed in such a way that users can find them by typing camel-cased partial names, eg In some cases we need to further filter the name matches to check if the class is-a Something… which we do by loading the class and using reflection. This is impractical if the user has only entered a single character as search term, or no characters at all. Obviously it's much faster to use ClassGraph to answer this question, and many others that we need to answer, but we don't know what info we need from the ScanResult up front. So my question is, is it inadvisable to leave the ScanResult hanging around for a long time? It's a server application so that could be months or longer. I'm aware that there is a memory consideration, and temporary files created etc, but would they cause a problem do you think? I haven't looked at the retained size of the ScanResult recently but as far as I remember, when I looked years ago, it was not significant (approx 60k classes). ClassGraph options are Another alternative is to index the ScanResult using Lucene then close it as usual, which would be fine except that's much harder than it should be due to the environment we operate in. I'd appreciate your thoughts if you have time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@jechlin great, I'm glad you have been getting some good usage out of ClassGraph! To answer your general question: You can keep a Probably ClassGraph should have another flag to enable access to Another possibility would be to close the Right now I think that when the In the next major version of ClassGraph, if I can find the time, I want to factor out all the optimized and multithreaded zipfile parsing and slicing code into a separate virtual filesystem library. Once that is done, a lot of the above dilemmas will become simpler to manage, since it will be easier to open or close resources as needed via the VFS API. Basically this would mean that in ClassGraph-5.x, to scan the classpath, you'd first fetch the classpath, then open all elements on the classpath, producing a list of resources by hierarchically scanning paths only. Then in a separate step, all classfiles from this resource list could be scanned, producing a list of Suggested solution for now: Because of the It sounds like you already call |
Beta Was this translation helpful? Give feedback.
@jechlin great, I'm glad you have been getting some good usage out of ClassGraph!
To answer your general question:
You can keep a
ScanResult
open as long as you want to, including for the whole lifetime of a program, as long as you don't mind keeping some resources open. This will typically include only file handles, but under some circumstances (or on some platforms), this may also include some memory-mapped files (memory mapping can be disabled). The reason for keeping files open is that the user might request the content of some resource from theScanResult
, and it would be inefficient to have to re-open jarfiles (potentially including jars-within-jars) to access each resource requeste…