Remote Debugging in Java

It’s a brief tutorial how to debugging remotely in Java by attaching to running jvm.

-Xdebug: Enables debugging support in the VM
jdwp: Java Debug Wire Protocol
suspend=n : Allows jdb to connect running jvm any time
address: Any process to debug will be connected via the port number written in the address..

We configured our program to accepts debugging requests. The remaining part is about how to connect it. I use IntellijIDEA as Java IDE , so the following part contains IntellijIDEA configuration for remote debugging.

On Run/Debug configuration windows, you can add new Remote Configuration as on the image above. Port should be same with the address on the jvm options. I attached a process that runs locally on my machine, you can override it.

Sources:
http://download.oracle.com/otn_hosted_doc/jdeveloper/904preview/jdk14doc/docs/tooldocs/windows/jdb.html

 

155 Words

Creating List of Beans in Spring

Let’s think we need a list of IMoveable in a class and I need to pass it through property injection in Spring. The easiest way is:

It seems fine if you have a few items and new items won’t be added. What if you have more items (eg 100)? What if another developer add pyramidMoveableObject and forget to add it into moveableObjectList?

In these scenarios, we have prettier way to do it. I a class to find all beans which implements IMoveable interfaces, more generally find beans of given types.

I’ll use 2 interface in my class

  1. FactoryBean inteface of Spring, to create list of items
  2. ApplicationContextAware interface to access beans in my context.
Then we can create our IMoveable list through the following beans:
At the end, our scene bean looks like this:
 

271 Words