There is no easy answer to this question. Almost certainly crustaceans don't perceive pain in the same way that a human does - their nervous system is set up completely differently from ours for a start. Some events that would be devastating to a human also don't seem to worry crustaceans too much - for example it is common to find crustaceans in the wild that are missing legs.
Barnacles start life as larvae or 'cyprids' which swim around freely in the water.
In order to complete the transition to adult life these cyprids must attach themselves to a hard substrate to enable an adult barnacle to develop. When the cyprid finds an appropriate hard substrate to settle on it starts to attach itself using the cement that was asked about. The cement is produced in glands at the base of the antennules, that passes through ducts running up the centre of the antennule and released through the tip. The glands are regenerated and remain active throughout life. As the barnacle grows, the cement glands increase in size and become more complex.