I want to know if there’s any way so I could watch for variable value change when the program is running. Of course not using debugger I wanna do it Programmatically. For example:
class A
{
public static int valueToBeWatched;
}
So at runtime if in any method of any class in my project modifies this value MyValueChangeListner event should get called.
You need to replace the type
intwith a class which will invoke your listener whenever the values changes. You might like to ignore setting the value when it hasn’t actually changed.e.g.
You can perform this replace using byte code injection, but it is much simple to change the original code.
An alternative is to monitor the value to look for changes periodically. Unless the value changes very slowly you might not see every change. You can use the Debugger API to do this but it not simple and I wouldn’t suggest you use it unless you are familiar with the API already.
Java Debugger API Links
http://java.sun.com/javase/technologies/core/toolsapis/jpda/
http://docs.oracle.com/javase/6/docs/technotes/guides/jpda/
http://docs.oracle.com/javase/6/docs/jdk/api/jpda/jdi/