Psalm 39 breaks from the pattern of several previous psalms. Often we find David crying out to God for help and deliverance, and at quick glance it seems that this psalm does the same thing. However, instead of just calling out to God, David addressed his readers and told them that he spoke to God and what he said.
He must have been going through a situation with his enemies (as in other psalms), because he told us that he had determined to keep his mouth shut and not speak to the issue (Psalm 39:1-3). However, that caused him to grow increasingly frustrated until he had to say something, so he vented at God.
In Psalm 39:4-6 it seems as if David was just pondering “the brevity of life.” Compared to God our short lives are nothing, just an accumulation of stuff until we fade away. Interestingly, the thought that we do not know “who will eventually haul it away” was repeated decades later by Solomon in Ecclesiastes 2:18-21. Without a close relationship with God, this life and all it offers is meaningless.
David finally came to his big point in Psalm 39:7-13. He acknowledged that he was, once again, being punished for his sin. Some of the imagery of God wounding and beating David are found in other psalms as well (e.g., Psalm 38). So, even though life itself is a “mere vapor,” it can be more so when under God’s discipline. David knew that only God could restore him to his former state of happiness and fulfillment, and the same principle is true for believers today.