0

Is it possible to kill a method loaded with reflection after a certain amount of time of the method executing? Consider the following:

public static void main(String[] args) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Class<?> cls = Class.forName("pkg1.pkg2.classname");
    Method method = cls.getMethod("main", String[].class);
    String[] params = null;
    method.invoke(null, (Object) params);
    // ... more code that does stuff after this
}

How would I let the main method run for a finite amount of time before a decision is made to just stop the dynamic invocation of the loaded main method but not the entire application?

djthoms
  • 3,026
  • 2
  • 31
  • 56
  • There's nothing special about using reflection when it comes to how long methods execute. It's the same as halting "a method" after a specific amount of time. – Erwin Bolwidt Feb 04 '16 at 04:26
  • @ErwinBolwidt thank you. I had no idea how to phrase what I'm trying to do. I'll look into this – djthoms Feb 04 '16 at 04:26

0 Answers0