0

I am working on enterprise level web application which build on J2EE. Project contains more than 1700 classes of different modules.

Some modules are not using across the people.

How can I know which classes are not using?

We already watched JVisualVm in sampler tab. But it just shows only active classes in memory. But It is not persistent . And also it does not show not initiated classes (dormant classes)

Expected Result : List of dormant classes (Not including dependencies)

For example :

package Structure:

root
|---- com
|    |---- A.java
|    |---- B.java
|    |---- C.java
|---- org
|    |---- D.java
|    |---- E.java
|    |---- F.java

All this class have annotation @Path some of them are being called from front end and some of them are not via ajax. Is there any way that we may come to know which class are being called or have a list of it?

As you can see it uses REST in java is it possible to know every time a new class is initialized by the Rest some how?

  • What you want exactly? Dependencies? or Loaded classes? – Jean-Baptiste Yunès Feb 22 '17 at 16:32
  • Question edited. I want only loaded cutsom classes not dependencies – Kunjal Bhatt Feb 22 '17 at 17:17
  • Observing the run time behaviour can only give you the information that a class is used, not that it is unused. It may be needed some time later. – Henry Feb 22 '17 at 17:24
  • @Henry If it is possible to make list of working classes by monitoring for 10 to 12 days.. that can make my solution – Kunjal Bhatt Feb 22 '17 at 17:27
  • @KunjalBhatt what if the class is needed for some exception handling and the problem triggering it occurs very seldom? This is similar to software testing: it can only show the presence of errors but not their absence. – Henry Feb 22 '17 at 18:05
  • Btw, did you have a look at the `-verbose:class` JVM option? – Henry Feb 22 '17 at 18:13

1 Answers1

0

Maybe greys-anatomy can help you.

sc:Search all the classes loaded by JVM

https://github.com/oldmanpushcart/greys-anatomy/wiki/Commands#sc

    ga?>sc -Sd Address*
    +------------------+---------------------------------------------------------------+
    |       class-info | Address                                                       |
    +------------------+---------------------------------------------------------------+
    |      code-source | /Users/vlinux/temp/                                           |
    +------------------+---------------------------------------------------------------+
    |             name | Address                                                       |
    +------------------+---------------------------------------------------------------+
    |      isInterface | false                                                         |
    +------------------+---------------------------------------------------------------+
    |     isAnnotation | false                                                         |
    +------------------+---------------------------------------------------------------+
    |           isEnum | false                                                         |
    +------------------+---------------------------------------------------------------+
    | isAnonymousClass | false                                                         |
    +------------------+---------------------------------------------------------------+
    |          isArray | false                                                         |
    +------------------+---------------------------------------------------------------+
    |     isLocalClass | false                                                         |
    +------------------+---------------------------------------------------------------+
    |    isMemberClass | false                                                         |
    +------------------+---------------------------------------------------------------+
    |      isPrimitive | false                                                         |
    +------------------+---------------------------------------------------------------+
    |      isSynthetic | false                                                         |
    +------------------+---------------------------------------------------------------+
    |      simple-name | Address                                                       |
    +------------------+---------------------------------------------------------------+
    |         modifier |                                                               |
    +------------------+---------------------------------------------------------------+
    |       annotation |                                                               |
    +------------------+---------------------------------------------------------------+
    |       interfaces |                                                               |
    +------------------+---------------------------------------------------------------+
    |      super-class | java.lang.Object                                              |
    +------------------+---------------------------------------------------------------+
    |     class-loader | sun.misc.Launcher$AppClassLoader@4554617c                     |
    |                  |   `-sun.misc.Launcher$ExtClassLoader@5cad8086                 |
    +------------------+---------------------------------------------------------------+
    |           fields | modifier : private                                            |
    |                  |     type : int                                                |
    |                  |     name : addressId                                          |
    |                  |                                                               |
    |                  | modifier : private                                            |
    |                  |     type : java.lang.String                                   |
    |                  |     name : addressName                                        |
    |                  |                                                               |
    |                  | modifier : private                                            |
    |                  |     type : double                                             |
    |                  |     name : avg                                                |
    +------------------+---------------------------------------------------------------+

    Affect(row-cnt:1) cost in 6 ms.
lichengwu
  • 4,277
  • 6
  • 29
  • 42