"2 phase commit" is a protocol for global transactions. A global transaction is one which happens over more than one distinct transactional resource. The "2 phase" part refers to the two distinct parts of the process, which work (roughly!) like this:
First, a coordination process starts and sends a prepare message to all the participants (the distinct transactional resources) - this message will include some sort of unique identifier. When they get the message, each of the resources do what they need to do to see if they can commit the transaction. If they can the respond with a vote commit message, or a vote abort message if they can't.
Second, the coordinator examines all the votes - if all the resources agree they can commit their specific transactions then a global commit message is send out, again with the unique ID. The resources now commit all their transactions.
In a J2EE app. you might use this sort of sequence of events to encapsulate a method which does a JDBC operation and some JMS stuff. Both the JDBC operation can fail and a JMS message can fail to be sent. If either fail inside an XA transaction (another common name for 2 phase commit) then the JDBC operation will be rolled back, and the JMS message will be removed.