Aryan Naraghi
Aryan Naraghi

Reputation: 273

Speeding up time when debugging in Eclipse

Is there a way to "speed up time" when debugging in Eclipse?

For instance, suppose you're debugging the following piece of code:

someFun();
Thread.sleep(ONE_MINUTE);
someOtherFun();

... when the Thread.sleep() method is reached, you have to wait one minute before being able to continue debugging. Is there a way to "speed up time" and have the sleep() method return immediately? (I understand that this speeding up can actually be dangerous, but let's assume it won't interfere with the correctness of the program.)

The next alternative would be wrap to Thread.sleep() and put it under a debug flag, but I'd like to avoid making such changes to the code.

Upvotes: 2

Views: 462

Answers (2)

Alex_M
Alex_M

Reputation: 1874

you could try to find out if the application is started in debug mode. depending on that you can set change the sleep time. but take care. especially if you work with thread.sleep(). the application could behave different depending on your use case.

public static final int ONE_SECOND = 1000;
public static final int ONE_MINUTE = 60 * ONE_SECOND;
public static final int SLEEP_TIME = (java.lang.management.ManagementFactory.getRuntimeMXBean().
    getInputArguments().toString().indexOf("-agentlib:jdwp") > 0)?ONE_SECOND:ONE_MINUTE;

Upvotes: 2

Ashwinee K Jha
Ashwinee K Jha

Reputation: 9307

Just before Thread.sleep is executed you can change the value of ONE_MINUTE from variables view using the change value option. This does not seem to work for final fields.

Another option could be to wrap the call to sleep in another method and you can "Force Return" from the method.

Upvotes: 1

Related Questions