I am trying to invoke a method in a class object via reflection. However, I want to run it as separate thread. Can someone tell me the changes I have to make on model.java or below code?
thread = new Thread ((StatechartModel)model);
Method method = model.getClass().getMethod("setVariable",newClass[]{char.class,t.getClass()});
method.invoke(model,'t',t);
Let me suggest a simpler version once you have your target object available as a
final
:You could do something like the following which just creates an anonymous
Runnable
class and starts it in a thread.