2 phase commit

Hello,
Can somebody help me to develop a “2 phase commit” transaction in Java? maybe some basic code example? the documentation is very poor.
Thanks in advance