The latest expert opinions, articles, and guides for the Java professional.

Testing JRebel

Quite a few of our users have contributed small pieces of code that test reloading of some parts of Java classes. Some of them have discovered genuine bugs and we are working on fixing them. However there was also some confusion that we want to clear up.

If you want to write a small test for JRebel you have to be aware of the two following things:

  • JRebel will not reload code of currently running method. All new invocations of the method (even concurrent ones) will get reloaded, but the code in a running method will not reload. This means that if you have a method with while (true) {/*body*/} the body will never reload since you never leave the method. This is not a restriction in any real application, but this does show up in the small tests.
  • The second issue is more particular to JRebel — if all running methods are of the same class they might not get reloaded (this does not always apply, but may compromise your test). This issue may come if you have only one class (e.g. Main) and try to change a method inside the same class.

The recommended way to test JRebel is to make a separate Launcher class with a while loop and call a method test() in another class (e.g. Test) with it. If you want to test concurrency make a separate class for threads (inner or anonymous will be enough).

Response (%)

  1. Avatar  

    Suraj BN

    March 8, 2013 @ 10:20 am

    Thank You. Those lines were really helpful =)

RSS feed for comments on this post. TrackBack URL

Leave a comment